Пример #1
3
  public void process(String[] arg) {
    if (arg.length != 13 && arg.length != 14) {
      System.out.println("Invalid number of arguments! " + arg.length);
      printUsage();
      System.exit(-1);
    }

    String sourceHost;
    String sourceUser;
    String sourcePass;
    int sourcePort;
    String queue;

    String targetHost;
    int targetPort;
    String targetUser;
    String targetPassword;
    String producingAddress;

    int commit;

    int waitTimeout;

    String filter = null;

    try {
      sourceHost = arg[1];
      sourcePort = Integer.parseInt(arg[2]);
      sourceUser = arg[3];
      sourcePass = arg[4];
      queue = arg[5];

      targetHost = arg[6];
      targetPort = Integer.parseInt(arg[7]);
      targetUser = arg[8];
      targetPassword = arg[9];
      producingAddress = arg[10];

      waitTimeout = Integer.parseInt(arg[11]);
      commit = Integer.parseInt(arg[12]);

      if (arg.length == 14) {
        filter = arg[13];
      }
    } catch (Exception e) {
      e.printStackTrace();
      printUsage();
      System.exit(-1);
      return; // the compiler doesn't understand exit as leaving the VM
    }

    Map<String, Object> sourceParameters = new HashMap<String, Object>();
    sourceParameters.put(TransportConstants.HOST_PROP_NAME, sourceHost);
    sourceParameters.put(TransportConstants.PORT_PROP_NAME, sourcePort);

    Map<String, Object> targetParameters = new HashMap<String, Object>();
    sourceParameters.put(TransportConstants.HOST_PROP_NAME, targetHost);
    sourceParameters.put(TransportConstants.PORT_PROP_NAME, targetPort);

    try {
      TransportConfiguration configurationSource =
          new TransportConfiguration(NettyConnectorFactory.class.getName(), sourceParameters);

      ServerLocator locatorSource = ActiveMQClient.createServerLocator(false, configurationSource);

      ClientSessionFactory factorySource = locatorSource.createSessionFactory();

      ClientSession sessionSource =
          factorySource.createSession(sourceUser, sourcePass, false, false, false, false, 0);

      ClientConsumer consumer;

      if (filter == null) {
        consumer = sessionSource.createConsumer(queue);
      } else {
        consumer = sessionSource.createConsumer(queue, filter);
      }

      TransportConfiguration configurationTarget =
          new TransportConfiguration(NettyConnectorFactory.class.getName(), targetParameters);

      ServerLocator locatorTarget =
          ActiveMQClient.createServerLocatorWithoutHA(configurationTarget);

      ClientSessionFactory factoryTarget = locatorTarget.createSessionFactory();

      ClientSession sessionTarget =
          factoryTarget.createSession(targetUser, targetPassword, false, false, false, false, 0);

      ClientProducer producer = sessionTarget.createProducer(producingAddress);

      sessionSource.start();

      int countMessage = 0;

      while (true) {
        ClientMessage message = consumer.receive(waitTimeout);
        if (message == null) {
          break;
        }

        message.acknowledge();

        if (!message.containsProperty("_HQ_TOOL_original_address")) {
          message.putStringProperty("_HQ_TOOL_original_address", message.getAddress().toString());
        }

        LinkedList<String> listToRemove = new LinkedList<String>();

        for (SimpleString name : message.getPropertyNames()) {
          if (name.toString().startsWith("_HQ_ROUTE_TO")) {
            listToRemove.add(name.toString());
          }
        }

        for (String str : listToRemove) {
          message.removeProperty(str);
        }

        producer.send(message);

        if (countMessage++ % commit == 0) {
          System.out.println("Sent " + countMessage + " messages");
          sessionTarget.commit();
          sessionSource.commit();
        }
      }

      sessionTarget.commit();
      sessionSource.commit();
      consumer.close();
      producer.close();

      sessionSource.close();
      sessionTarget.close();

      locatorSource.close();
      locatorTarget.close();

    } catch (Exception e) {
      e.printStackTrace();
      printUsage();
      System.exit(-1);
    }
  }
Пример #2
0
  public static String getJMSType(Message message) {
    SimpleString ss = message.getSimpleStringProperty(TYPE_HEADER_NAME);

    if (ss != null) {
      return ss.toString();
    } else {
      return null;
    }
  }
Пример #3
0
 @Override
 public String getStringProperty(String name) {
   try {
     SimpleString prop = properties.getSimpleStringProperty(new SimpleString(name));
     if (prop == null) return null;
     return prop.toString();
   } catch (ActiveMQPropertyConversionException ce) {
     throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
     throw new JMSRuntimeException(e.getMessage());
   }
 }
Пример #4
0
  public static void clearProperties(Message message) {

    List<SimpleString> toRemove = new ArrayList<SimpleString>();

    for (SimpleString propName : message.getPropertyNames()) {
      if (!propName.startsWith(JMS) || propName.startsWith(JMSX) || propName.startsWith(JMS_)) {
        toRemove.add(propName);
      }
    }

    for (SimpleString propName : toRemove) {
      message.removeProperty(propName);
    }
  }
Пример #5
0
  @Override
  public Set<String> getPropertyNames() {
    try {
      Set<SimpleString> simplePropNames = properties.getPropertyNames();
      Set<String> propNames = new HashSet<String>(simplePropNames.size());

      for (SimpleString str : simplePropNames) {
        propNames.add(str.toString());
      }
      return propNames;
    } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
    } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
    }
  }
Пример #6
0
  public LocalQueueBinding(
      final SimpleString address, final Queue queue, final SimpleString nodeID) {
    this.address = address;

    this.queue = queue;

    filter = queue.getFilter();

    name = queue.getName();

    clusterName = name.concat(nodeID);
  }
Пример #7
0
  public static Set<String> getPropertyNames(Message message) {
    HashSet<String> set = new HashSet<String>();

    for (SimpleString propName : message.getPropertyNames()) {
      if ((!propName.startsWith(JMS) || propName.startsWith(JMSX) || propName.startsWith(JMS_))
          && !propName.startsWith(CONNECTION_ID_PROPERTY_NAME)) {
        set.add(propName.toString());
      }
    }

    set.add(JMSXDELIVERYCOUNT);

    return set;
  }
Пример #8
0
 /**
  * Sets all properties we carry onto the message.
  *
  * @param message
  * @throws JMSException
  */
 private void setProperties(Message message) throws JMSException {
   for (SimpleString name : properties.getPropertyNames()) {
     message.setObjectProperty(name.toString(), properties.getProperty(name));
   }
 }
Пример #9
0
  @Override
  public ServerConsumer createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly,
      final boolean supportLargeMessage,
      final Integer credits)
      throws Exception {
    if (this.internal) {
      // internal sessions doesn't check security

      Binding binding = postOffice.getBinding(queueName);

      if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(queueName);
      }

      Filter filter = FilterImpl.createFilter(filterString);

      ServerConsumer consumer =
          newConsumer(
              consumerID,
              this,
              (QueueBinding) binding,
              filter,
              started,
              browseOnly,
              storageManager,
              callback,
              preAcknowledge,
              strictUpdateDeliveryCount,
              managementService,
              supportLargeMessage,
              credits);
      consumers.put(consumer.getID(), consumer);

      if (!browseOnly) {
        TypedProperties props = new TypedProperties();

        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());

        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());

        Queue theQueue = (Queue) binding.getBindable();

        props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());

        // HORNETQ-946
        props.putSimpleStringProperty(
            ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));

        props.putSimpleStringProperty(
            ManagementHelper.HDR_REMOTE_ADDRESS,
            SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));

        props.putSimpleStringProperty(
            ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));

        if (filterString != null) {
          props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
        }

        Notification notification =
            new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);

        if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
          ActiveMQServerLogger.LOGGER.debug(
              "Session with user="******", connection="
                  + this.remotingConnection
                  + " created a consumer on queue "
                  + queueName
                  + ", filter = "
                  + filterString);
        }

        managementService.sendNotification(notification);
      }

      return consumer;
    } else {
      return super.createConsumer(
          consumerID, queueName, filterString, browseOnly, supportLargeMessage, credits);
    }
  }