0

I have a server which publishes rabbitmq messages on a exchange, so I tried to create following async api specs for this -

asyncapi: 2.3.0
info:
  title: Hello World
  version: 1.0.0
  description: Get Hello World Messages
  contact: {}
servers:
  local:
    url: amqp://rabbitmq
    description: RabbitMQ
    protocol: amqp
    protocolVersion: 0.9.1
defaultContentType: application/json
channels:
  hellow_world:
    subscribe:
      operationId: HelloWorldSubscriber
      description: 
      message:
        $ref: '#/components/messages/HellowWorldEvent'
      bindings:
        amqp:
          ack: true
          cc: ["hello_world_routing_key"]
        bindingVersion: 0.2.0
    bindings:
      amqp:
        is: routingKey
        exchange:
          name: hello_world_exchange
          type: direct
          durable: true
          vhost: /
        bindingVersion: 0.2.0
components:
  messages: 
    HellowWorldEvent:
      payload:
        type: object
        properties: []

Based on my understanding what it means is that MyApp will publish helloworldevent message on hello_world_exchange exchange using routing key hello_world_routing_key

Question -

  • How can consumer/subscriber can define which queue he will be using for consuming this message ?
  • Do I need to define new schema for subscriber and define queue element there ?
  • I can define another queue.** elements in channel element, but that can only specify 1 queue element, what if there are more than 1 subscriber/consumer, so how we can specify different queues for them ?

Reference - https://github.com/asyncapi/bindings/tree/master/amqp

shivMagus
  • 315
  • 4
  • 9
  • Normally you only specify topics via async api. The queue is an implementation detail of the application. But to answer your question i need to know the broker your are using. – GreenRover May 05 '22 at 11:19
  • I am using RabbitMQ – shivMagus May 05 '22 at 12:14
  • This might help you: https://github.com/rabbitmq/rabbitmq-tutorials/blob/master/python/receive_logs.py What application/framework you use to receive the messages? – GreenRover May 05 '22 at 13:48
  • I am using python/pika. – shivMagus May 05 '22 at 17:47
  • I am more from the java world but this should be an god example. https://github.com/pika/pika/blob/master/examples/asynchronous_consumer_example.py#L28 You listen on the topic "message" that is defined in your async api spec. But to do this persistend, a queue named "text" is created that not have be part of the spec. – GreenRover May 06 '22 at 06:23

1 Answers1

1

I see you have not yet approved any of the responses as a solution. Is this still an issue? Are you using the AsyncAPI generator to generate your code stubs?

If so the generator creates a consumer/subscriber. If you want different processing/business logic you would generate new stubs and configure the queues they listen from. The queue is an implementation detail. I had an issue with the node.js generator for AMQP and RabbitMQ and so I decided to test the spec against Python to see if it was me or the generator.

Try the generator and you can try my gist: https://gist.github.com/adrianvolpe/27e9f02187c5b31247aaf947fa4a7360. I did do this for version 2.2.0 so hopefully it works for you.

I also did a test with the Python pika library however I did not assign a binding to the queue.

I noticed in the above spec you are setting your exchange type to Direct. You can have the same binding with multiple consumers with both Direct and Topic exchanges however you may want Topic as quoted from the RabbitMQ docs:

https://www.rabbitmq.com/tutorials/tutorial-five-python.html

Topic exchange is powerful and can behave like other exchanges.

When a queue is bound with "#" (hash) binding key - it will receive all the messages, regardless of the routing key - like in fanout exchange.

When special characters "*" (star) and "#" (hash) aren't used in bindings, the topic exchange will behave just like a direct one.

Best of luck!

avolpe
  • 26
  • 1
  • - thanks for suggestion on topic exchange and example schema file. - i guess u r right that queue is more like a implementation detail which will vary based on underlying frameworks, in case of rabbitmq as queue as some additional details like persistency etc, so i was hoping if asyncapi provides some way to define these details as well or ingeneral how other using asyncapi in context of rabbitmq define these details. thanks for your help. – shivMagus May 21 '22 at 08:05