amqp egress connector

AMQP Egress Connector

Version: 17.07

Supported Since: 17.01

What is AMQP Egress Connector?

AMQP Egress connector can be used to send messages to AMQP destinations from the UltraESB. When using AMQP Egress Connector you can use it with a transactional AMQP Ingress Connector or with a CallbackHandler

You can either use transactional (transaction mode) or Callback Handler (confirm mode) with a specified Connection Factory
In order to use the AMQP Egress Connector, you must first select the AMQP Connector dependency from the connector list when you are creating an empty Ultra project. If you have already created a project, you can add the AMQP Connector dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list, select the AMQP Connector dependency.
amqp egress connector 11

Out Ports

On Exception

The message will be emitted from this out port if the Egress Connector failed to process the message due to some reason

Response Processor

The message will be emitted from this out port if the Complete Flow property is disabled and the message has been sent to the AMQP destination successfully

Side Ports

Connector Operation

This port is used to connect operational elements to the Egress Connector. By-default, user does not have to connect any operational element and the default connector operation will be used.

Parameters

* marked fields are mandatory

AMQP Template *

Basic

The org.springframework.amqp.core.AmqpTemplate instance to be used in-order to send messages to destination queue.

Destination *

Basic

Name of the destination queue

Callback Handler

Advanced

Callback object to be invoked when async response received from the MQ server when a message is sent notifying its received status by the server. Users can specify their custom implementations of org.adroitlogic.x.base.trp.SendCallback class as the Callback Handler as well.

Complete Flow

Advanced

If true, the integration flow will be completed once the message has been sent to the AMQP destination. If false, the original message sent to the AMQP destination will be emitted to the Response Processor out port to continue the flow

Weight

Fail-Over

Weight for the Egress Connector if Egress Load Balancer element is used with Weighted/Weighted with Failover algorithm is used.

Sample Use Case

Prerequisite

First you need to specify a Connection Factory to connect to the AMQP Server. For this example let’s use Rabbit MQ and if you have not already installed Rabbit MQ, please follow the Installation Guide

1. Sending a message to an AMQP queue in transaction mode

In-order to use the transaction mode, you must first add the required resources in the project.xpml file. Right click on project.xpml file and from the context menu, select Resource Template as shown in below figure

amqp egress connector 1

After that from the shown dialog box, select RabbitMQ with Transaction template.

amqp egress connector 2

Next you need to specify the required parameters as shown below. It is mandatory to specify a bean prefix and for that you can specify any value. Apart from that you need to specify the host and port of the RabbitMQ server.

amqp egress connector 3

Now let’s see how we can send a message obtained from a remote RabbitMQ queue can be sent to multiple destination queues as an atomic operation through a transaction. First create the flow as shown below

amqp egress connector 4

As you can see, there is one AMQP Ingress Connector with a transaction manager specified, and Channel Transacted enabled (under Transaction tab in the property pane) and within the transaction scope there are two AMQP Egress Connectors to send the message to two destination queues. After sending the message to both queues, we are closing the transaction scope and completing the integration flow with a Successful Flow End component. If you run the project, you can see that the original message has been sent to both destination queues.

Now if we add an Exceptional Flow End element after the second AMQP Egress Connector, you can see that message flow completes with an exception while the transaction scope is still active. In this case, the original message is not sent to the either of destination queues and rolled back to the source queue.

amqp egress connector 5

This happens because when we specify the transaction manager to the AMQP Ingress Connector and include the Egress Connectors within the same transaction scope, all AMQP queueing/de-queuing operations are bounded with a singe transaction and if the message flow fails within the transaction scope (since the transaction scope is not closed), the transaction will be rolled back.

It should be noted that for a for the AMQP Ingress/Egress connectors to be bound by a single transaction, the AMQP template MUST use the same AMQP Connection Factory used by the Ingress Connector

Now suppose you are getting a message from a non-transactional transport like HTTP. As shown in the below image, even in this case we can sent the message to multiple destination AMQP queues in a single transaction.

amqp egress connector 6

Although, in here you need to specify the transaction manager in the TransactionScopeStartElement as shown below.

amqp egress connector 7

Now if you modify the flow as below and run the project again, you can see that the message has not been sent to either of the AMQP destinations.

amqp egress connector 8
When you specify a transaction manager to the AMQP Ingress Connector, it is given the highest priority and the transaction manager specified in the TransactionScopeStartElement is ignored. But once you include a TransactionScopeEndElement and finish the transaction started by the transaction manager of the AMQP Ingress Connector, for all the subsequent transaction scopes, the transaction manager specified in the TransactionScopeStartElement will be used.
amqp egress connector 9

As an example in the above flow, the same transaction manager is specified for AMQP Ingress Connector, TransactionScopeStartElement and TransactionScopeEndElement. If any exception occurs within the transaction scope (A), the message will be rolled back to the original source queue and message will not be sent to any of the destination queues.

If any exception occurs within the transaction scope (B), then the message will be sent to the destination X, Y, but the message will not be sent to either of destinations P, Q.

2. Sending a message to an AMQP queue in confirmation mode

When using the confirmation mode, you need to add a callback handler. In the project.xpml as mentioned previously, go to the "Resource Template" section and select RabbitMQ with Callback. Next, specify the required properties and save the pop-up modal. Now you can see that the required resources are added to the project.xpml file.

Now let’s create a simple flow as shown below

amqp egress connector 10
In the above flow you should only specify the connection factory and the source queue name in the AMQP Ingress Connector. As for the Egress Connector, specify the AMQP template and a non-existing queue name so that the rabbit server exchange will fail to route the message to a destination queue. Further, under the Advanced category of the Egress Connector, select the confirmReturn Callback Handler and

Now if you run this flow and send a message you will see an error message similar to below one

ERROR RabbitConfirmAndReturnCallback Returned message  with reply code 312 and reply test NO_ROUTE from exchange '' with routing key 'nonQueue'

This means that the rabbit server has failed to find the destination queue and the message delivery has failed which results in a message flow failure.

In this topic
In this topic
Contact Us