1

I have existing RabittMQ server set-up and we enabled MQTT plug-in to publish/subscribe mqtt messages. We have pika client to process the existing queue messages . Right now , we want to use the same pika on_message() handler to process the mqtt message. I am able to publish and subscribe mqtt message over eclipse paho client . We want to use the existing RabittMQ client(pika). MQTT plug-in by default publish to amq.topic exchange . I want to publish the same message to my own exchange. Please let me know , how to get this.

JavaUser
  • 25,542
  • 46
  • 113
  • 139

1 Answers1

3

The RabbitMQ team monitors this mailing list and only sometimes answers questions on StackOverflow.

If you want a consumer using the Pika library to receive MQTT messages that consumer must subscribe to the appropriate queue to which the MQTT messages are being published. Comprehensive documentation of how MQTT and AMQP can interoperate is available here.

You then say "I want to publish the same message to my own exchange". If you wish to use your own exchange instead of amq.topic, please see the "Custom Exchanges" section of this document. You must specify the name of the exchange in the rabbitmq.config file and create the exchange prior to publishing any messages. Note that this custom exchange must be a topic exchange.

The RabbitMQ documentation is a good resource and I suggest searching there when you have questions.

Luke Bakken
  • 8,993
  • 2
  • 20
  • 33
  • Thanks Luke . I am successfully publishing message from mqtt client and receiving it in RabbitMQ . I set custom exchange in config file. – JavaUser Nov 14 '17 at 06:03
  • Great, thanks for letting me know. If you don't mind, please mark my response as the accepted answer. Thank you. – Luke Bakken Nov 14 '17 at 14:39
  • @LukeBakken, I can send messages from a client to the RabbitMQ broker with both `paho` and `pika` (as producer). However, when observing the connection, I can see that the connections were established with `MQTT 3.1.1` and `AMQP 0-9-1` respectively. However, paho-based pub is not stored in RabbitMQ unless the topic of the pub is not bound in the consumer/producer's queue (with 'amq.topic' exchange). The pub topic still can work even though the queue is in 'Idle' state (not producing/consuming data/messages). **Is it possible to make a mqtt-based connection with `pika`?** – testuser Feb 09 '23 at 11:25
  • 1
    @testuser Pika only supports AMQP, but you should be able to get the two applications to communicate. The best way for me to assist you is for you to provide a git repository where I can review your code and provide feedback (perhaps via a pull request). Thanks. – Luke Bakken Feb 09 '23 at 15:08
  • @LukeBakken, please a look at [this git repo](https://github.com/engrjislam/pub_sub_with_rabbitmq_and_mosquitto). – testuser Feb 09 '23 at 19:15
  • https://github.com/engrjislam/pub_sub_with_rabbitmq_and_mosquitto/issues/1 – Luke Bakken Feb 09 '23 at 23:54
  • @LukeBakken, I got my answer on your previous reply. I tried to send MQTT request from the producer. Unfortunately, the producer (written with pika) only support AMQP (but completable with MQTT). I was not able to send MQTT packet from pika-based producer. When I was check documentation in pypi, I saw that pika is implemented with AMQP. – testuser Feb 10 '23 at 07:08
  • Yes, but I should be able to figure out how to send data from a Pika producer that will be consumed by an MQTT consumer. There's nothing stopping it in RabbitMQ. I see that you deleted your repository but I still have my fork. I will continue to investigate this because AMQP and MQTT compatibility is one of RabbitMQ's features. – Luke Bakken Feb 10 '23 at 21:12
  • @LukeBakken, I haven't deleted the repo but made that private. Now, I make it public. However, I checked the header (when consumer received a new message from a paho-mqtt based publisher) which is nothing but '{'x-mqtt-publish-qos': 0, 'x-mqtt-dup': False}'. I tried to bound the header with producer. I was expecting to have an MQTT connection as I put it in the producer but unfortunately, the header does not resolve this. The connection is established with AMQP protocol rather MQTT. How can make an MQTT connection with pika producer (like as phao-mqtt)? N.B.: removed unnecessary codes. Thanks! – testuser Feb 11 '23 at 11:15
  • 1
    Again, Pika will ONLY create AMQP connections, but you should be able to send data from a Pika AMQP *producer* to a Paho MQTT *consumer*. I will check out your code. – Luke Bakken Feb 12 '23 at 15:43