Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
minLevel1
maxLevel3
outlinefalse
typelist
printablefalse

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
languageyaml
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
languagejson
{
  "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
colourBlue
titleSINCE VERSION 9.0

...

  • 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
colourBlue
titleSince version 10

...

Info

Note: Even if you set autoack to false, a message ACK will be send at the very end of a successful pipeline execution if not done before manually using message.ack. The similar is true in case of an error in the pipeline: In this case the action defined by failureAction will be applied on the message. This is to keep in sync with the RabbitMQ specification, as it requires an answer with ACK, NACK, or DROP after a while to keep the connection healthy.

Sending Messages

To send messages in a pipeline, you can use the command message.send.

...