Subscribing to a queue and publishing to Exchange Fanout
The Devprime platform natively supports RabbitMQ, an open-source messaging software that operates on the basis of Advanced Message Queuing Protocol (AMQP). Use an exchange fanout and subscribe to a queue.
Subscribe to a queue in RabbitMQ using a “Fanout” Exchange
In the JSON example below, the “Exchange” and “ExchangeType” parameters have been added, setting the Exchange type to “fanout” and using the queues item to “in-fanout-01”.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
"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": [
{
"Exchange": "dp-fanout",
"ExchangeType": "fanout",
"queues": "in-fanout-01"
}
]
}
],
|
YAML example with application settings:
1
2
3
4
5
6
|
- 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=5|||
subscribe=[exchange=dp-fanout,exchangetype=fanout,queues=in-fanout-01]"
|
Setting Up Publish/Subscribe Using an Exchange “Fanout”
In the example presented in the JSON below, you will notice that in addition to the “Subscribe” parameter in the Exchange “dp-fanout”, we have added a “Publish” parameter to allow the publication of events in the Exchange Fanout “dp-fanout-global”. In the example, you can also see the “Subscribe” in the “ms-order-in” queue, linked to the default Exchange “devprime”.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
"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",
"Publish": [
{
"Exchange": "dp-fanout-global",
"ExchangeType": "fanout"
}
],
"Subscribe": [
{
"Exchange": "dp-fanout",
"ExchangeType": "fanout",
"queues": "in-fanout-01"
},
{
"queues": "ms-order-in"
}
]
}
],
|
Example in the application log with this configuration:
1
2
3
|
[INF][ms-order][Stream][Type "RabbitMQ"][Alias "Stream1"]
["Enable"][Subscribe]["in-fanout-01,ms-order-in"]
[Parallel "30"][Buffer "1"]
|
YAML example with application settings:
1
2
3
4
5
6
7
8
|
- 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=5|||
publish=[exchange=dp-fanout-global,exchangetype=fanout]|||
subscribe=[exchange=dp-fanout,exchangetype=fanout,queues=in-fanout-01]
[queues=ms-order-in]"
|
Last modified August 20, 2024 (2f9802da)