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

    Setting transport connector programmatically for asynchronous dispatching

    Torsten Mielke Apprentice

      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");  


      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()) {
          if (taskRunner == null) {
          } else {
            synchronized(dispatchQueue) {
            try {
            } catch (InterruptedException e) {


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

        • 1. Re: Setting transport connector programmatically for asynchronous dispatchi
          Glen Klyuzner Newbie

          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:

          2 -> tcp:

          3 -> http:

          4 -> ssl:


          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