1 Reply Latest reply on Jun 19, 2008 2:31 PM by gklyuzner

    Setting transport connector programmatically for asynchronous dispatching

    mielket

      If you programmatically set up a transport connector in your ActiveMQ broker and you want to use asynchronous message delivery, then use the following code snippet:

       

      BrokerService _brokerService = new BrokerService();
      TransportConnector connector = _brokerService.addConnector("tcp://localhost:61616");  
      connector.setTaskRunnerFactory(brokerService.getTaskRunnerFactory());
      connector.start();
      ...
      

       

      The call to setTaskRunnerFactory() is required so that a thread for asynchronous dispatching can be created when needed. Otherwise synchronous dispatching will be used. Have a look at the implementation of dispatchAsync() in class org.apache.activemq.broker.TransportConnection:

       

      public void dispatchAsync(Command message) {
        if (!stopping.get()) {
          //getStatistics().getEnqueues().increment();
          if (taskRunner == null) {
            dispatchSync(message);
          } else {
            synchronized(dispatchQueue) {
              dispatchQueue.add(message);
            }
            try {
              taskRunner.wakeup();
            } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
            }
          }
        }
        ...
      }
      

       

      As you can see if no taskRunner is assigned, the message will be dispatched synchronously.

        • 1. Re: Setting transport connector programmatically for asynchronous dispatchi
          gklyuzner

          Cool, I just thought about the same, but about Prioritized connections.

           

          It would be nice to have ability in ActiveMQ  to choose dynamically or/and on a per topic basis, the appropriate transport/connection for the topic being published.

          Sometime in some legacy applications the same logical pipe (Destination) is used for different types of messages, which requires different QoS. Some could be send via slow low priority transport, but some should be sent as fast as possible.

           

          So, it could be implemented the same as fast switching failover connection.

           

          Based on xml conf file the factory could allocate several connections which could be chosen based on JMS Message priority or JMSProperty.

          In addition the config could assign certain default priority for each message priority or detination(it could be done as simple mapping).

          Conn Priority to Transport

          1 -> udp:
          brokerhost:61131

          2 -> tcp:
          brokerhost:61132

          3 -> http:
          brokerhost:61133

          4 -> ssl:
          brokerhost:61134

           

          JMS defines a 10 level priority value with 0 as the lowest and 9 as the highest.

           

          JMS Priority  Conn Priority

          0 -> 4

          1 -> 4

          2 -> 4

          3 -> 3

          4 -> 3

          5 -> 2

          6 -> 2

          7 -> 2

          8 -> 1

          9 -> 1

           

          Ect same for Destinations with wildcard patterns