Subscribing to a queue in RabbitMQ

The Devprime platform natively supports RabbitMQ, an open source messaging software that operates on the Advanced Message Queuing Protocol (AMQP) and Streaming Text Oriented Messaging Protocol (MQTT) protocols.

RabbitMQ can be used on-premise, cloud, docker, kubernetes and managed platforms such as CloudAMQP and others.

Subscribe to a queue in RabbitMQ

The JSON below demonstrates the default configuration with the RabbitMQ credentials, the exchange used, the Retry, the Fallback, the Threads and the ‘Subscribe’ option to receive events in the ‘orderevents’ queue as defined in the Queues item.

Standard Configuration Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
"DevPrime_Stream": [
    {
      "Alias": "Stream1",
      "Enable": "true",
      "Default": "true",
      "StreamType": "RabbitMQ",
      "HostName": "Localhost",
      "User": "guest",
      "Password": "guest",
      "Port": "5672",
      "Exchange": "devprime",
      "ExchangeType": "direct",
      "Retry": "3",
      "Fallback": "State1",
      "Threads": "30",
      "Buffer": "1",
      "Subscribe": []
    }
  ],

RabbitMQ configuration example with subscription in the topics: notifications and paymentevents
When adding more than one topic, it is necessary to separate them by a comma “,” as demonstrated.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"DevPrime_Stream": [
    {
      "Alias": "Stream1",
      "Enable": "true",
      "Default": "true",
      "StreamType": "RabbitMQ",
      "HostName": "Localhost",
      "User": "guest",
      "Password": "guest",
      "Port": "5672",
      "Exchange": "devprime",
      "ExchangeType": "direct",
      "Retry": "3",
      "Fallback": "State1",
      "Threads": "30",
      "Buffer": "1",
      "Subscribe": [
        {
          "Queues": "notifications, paymentevents"
        }
      ]
    }
  ],

In the example below, we’re detailing the default Adapter settings and the RabbitMQ-specific settings.

General
Enable Enable the Stream adapter (True/False)
Alias Define a unique name to identify the service
Default Sets the default for the centary to have more than one Stream (True/False)
StreamType Sets the Stream Type (RabbitMQ/Kafka)
HostName Configure the RabbitMQ
User Configures the user to connect
Password Configures the user’s password
Port Configure the port
Exchange Configures the default RabbitMQ
ExchangeType Configures the Exchange type
Retry Sets the number of retries
Fallback Sets a State for automatic persistence in case of failure
Threads Sets the number of concurrent connections processing events
Buffer Sets the number of events obtained per connection
Subscribe Configures RabbitMQ queues for read

Example in the application log with this configuration:

1
2
[INF][ms-order][Stream][Type "RabbitMQ"][Alias "Stream1"]
["Enable"][Subscribe]["orderevents"][Parallel "30"][Buffer "1"]

YAML example with application settings:
To export the configurations as an environment variable and use in Kubernetes, run the command in the Devprime CLI:
dp export kubernetes

1
2
3
4
5
- name: devprime_stream1
  value: "alias=Stream1|||enable=true|||default=true|||streamtype=RabbitMQ|||
  hostname=rabbitmq.default.svc|||user=guest|||password=guest|||port=5672|||
  exchange=devprime|||exchangetype=direct|||retry=3|||fallback=State1|||
  threads=30|||buffer=1|||subscribe=[queues=orderevents]"
Last modified August 20, 2024 (2f9802da)