...
Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
What is Messaging?
PIPEFORCE has a built-in messaging system where application messages can be routed between microservices based on conditions, like routing keys, for example.
...
This section will cover the second part: How to write pipelines which send and receive messages to/from the messaging broker.
Receiving messages
Receiving messages in a pipeline is simple: Use the command message.receive and specify the message key of interest. After you have stored the pipeline, it will be executed every time this key occurs. No need to manage connections, queues, bindings or similar.
...
After you stored it, the pipeline then starts to listen: Any time a message with key sales.order.created
happens, this pipeline will be informed about this and executes any command below message.receive
. So in this example this will send a new email any time this message happens.
Managed Queue
PIPEFORCE can manage the creation, registration and deletion of exchanges, consumers, queues and bindings automatically for you.
...
If you delete or change a message.receive
command inside a pipeline, the according consumer will be removed, but the queue and bindings will not be deleted by default.
How to change the default?
You can change this default behaviour by using the parameter manageQueue
which can be set to these values:
...
Regardless of the parameter manageQueue
, the creation, deletion and scaling of the according consumer is always done automatically.
Accessing Payload
It's also possible to send message with additional data: Which is called the payload.
...
Code Block | ||
---|---|---|
| ||
pipeline: - message.receive: key: "sales.order.created" - mail.send: to: "sales@company.tld" subject: "New Sales Order" message: | Hello, a new sales order has been created: Id: ${body.id} Date: ${body.date} Amount: ${body.amount} Customer: ${body.customer} |
Non JSON payload
In case you're sending a message in a non JSON format, for example as a simple text string Hello World!
, it will be internally wrapped into a JSON envelope using this structure:
Code Block | ||
---|---|---|
| ||
{ "status": 200, "valueType": "string", "value": "Hello World!" } |
Using Wildcard Keys
In some situations you probably would like to listen to all messages of a certain type. So lets assume you would like to be informed about any sales order changes in the sales department and let's assume the integration team publishes all changes to a message key structure like this:
...
The hash #
matches any level of the message key regardless of the number of periods (sections) in it.
Batched Messages
Sometimes it is required to execute the message listener only for a bunch of messages, not for each single one. This is useful for example for performance reasons in case you have a lot of tiny messages or in case the target accepts only groups of messages. For this you can use the messaging batching feature of PIPEFORCE using these parameters on the message.receive
command:
...
The messages in the buffer are not acknowledged until they got delivered to the pipeline.
Auto and manual ACK, NACK and DROP
Status | ||||
---|---|---|---|---|
|
...
message.ack
= Sends a message ACK so the current message will be removed from the queue.message.nack
= Sends a message NACK so the current message will be returned to queue and the pipeline will be re-executed again after a while.message.drop
= Sends a message DROP so the current message will be removed from the queue and will be added to the default dead letter queue for this pipeline.
Retry parameters
Status | ||||
---|---|---|---|---|
|
...
Info |
---|
Note: Even if you set |
Sending Messages
To send messages in a pipeline, you can use the command message.send.
...