Krutik
Krutik

Reputation: 243

Is MQTT support queue in ActiveMQ?

I am new tot this and learning about this protocol. While reading on wiki about MQTT. the first line "MQTT[1] is a publish-subscribe based "light weight" messaging protocol for use on top of the TCP/IP protocol."

Does this mean that MQTT only support Topic and not support or work with queue?

Because, Even I check out with available Client API (fusesource and paho). I dint found client API for Queue.

Upvotes: 2

Views: 11778

Answers (4)

mookins
mookins

Reputation: 71

MQTT has no understanding of queues as per JMS or many other messaging systems. MQTT only understands topics which can be published and subscribed to.

The solution I came to using ActiveMQ 5.13.1 as the MQTT broker was to include a composite topic to which the MQTT client will send to. ActiveMQ will pick up the messages written to the topic and write them to a queue (or multiple queues or topics) as per your configuration. Keep in mind that the topic name will have the periods changed to forward slashes, so for instance, the topic name in the given example, LOCAL.EC.T, will become LOCAL/EC/T. This was true at least for my test setup using Eclipse Paho Client MQTTv3 1.0.2 and I believe this is an MQTT implementation detail.

${ACTIVEMQ_HOME}/conf/activemq.xml configuration.

<beans>
    <broker>
        ...
        <destinationInterceptors>
            <virtualDestinationInterceptor>
                <virtualDestinations>
                    <compositeTopic name="LOCAL.EC.T">
                        <forwardTo>
                            <queue physicalName="LOCAL.EC.Q.1" />
                            <queue physicalName="LOCAL.EC.Q.2" />                       
                        </forwardTo>
                    </compositeTopic>
                </virtualDestinations>
            </virtualDestinationInterceptor>
        </destinationInterceptors>
        ...
    </broker>
</beans>

This is the reference I used.

Upvotes: 1

Dayanand Waghmare
Dayanand Waghmare

Reputation: 3078

MQTT not supports queue if you want to implement Queue with ActiveMQ use STOMP protocol check this link https://github.com/asantos2000/RabbitMQGozirraStompAndroid

if you want to use Topic just used QUEUE_NAME= /topic/nameof_topic and if you want to use Queue used destination QUEUE_NAME=/queue/nameof_queue

for filter message in queue add selectors

 Map<String,String> header=new HashMap<String, String>();
 header.put("selector","(title = 'selector_name')");
con.subscribe(QUEUE_NAME, new Listener() {
                @Override
                public void message(Map header, String body ) {
                    Log.d(TAG,"onMessage()");
                    Log.d(TAG,"message is " + body);
                    Log.d(TAG,"header is " + header.toString());
                    message = "\n("+ counterReceive +")<-- " + body;
                    myHandler.post(myRunnable);
                    counterReceive++;
                }
            },header);

you will get only those message which header contain your selector name

Upvotes: 1

hardillb
hardillb

Reputation: 59866

Yes, MQTT is topic only, there is no queue support

Upvotes: 1

ppatierno
ppatierno

Reputation: 10075

ActiveMQ supports MQTT and you can read much here :

http://activemq.apache.org/mqtt.html

In the last weeks the acronym of Message Queue Telemetry Transport is changed in MQ Telemetry Transport because MQTT hasn't queue concept ! :-)

As @hardillb said, publish and subscribe operations are executed on topics.

A concept of "queue" is implemented only when you use advanced "clean session" to false features that implies to broker to save messages published on a topic where a client is offline, so that when the client will return online, it will receive the messages. However, this implementation is strictly related to the broker (not necessary with a queue).

I wrote the following free ebook (focused on Microsoft techonologies) but the chapter 3 is dedicated to MQTT protocol itself.

http://www.embedded101.com/DevelopM2MIoTDevicesEbook.aspx

Paolo.

Upvotes: 4

Related Questions