Storing and Forwarding Messages

This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Storing and Forwarding Messages

Store and forward messaging is used for serving traffic to back-end services that can accept request messages only at a given rate. This is also used for guaranteed delivery to ensure that request received never gets lost since they are stored in the message store and also available for future reference. 

In this tutorial, instead of sending the request directly to the back-end service, you store the request message in the Message Broker profile of WSO2 EI. You then use a Message Processor to retrieve the message from the store and then deliver the message to the back-end service.

See the following topics for a description of the concepts that you need to know when creating WSO2 EI artifacts:

Before you begin,

  1. Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.

  2. Download the WSO2 EI ZIP file from here, and then extract the ZIP file. 
    The path to this folder will be referred to as <EI_HOME> through out this tutorial.

  3. Select and download the relevant EI tooling ZIP file based on your operating system from here and then extract the ZIP file.
    The path to this folder will be referred to as <EI_TOOLING> through out this tutorial.

  4. If you did not try the Exposing Several Services as a Single Service tutorial yet, open the WSO2 EI Tooling environment, click File, and then click Import. Next, select Existing WSO2 Projects into workspace under the WSO2 category, click Next and upload the pre-packaged project. This contains the configurations of the Exposing Several Services as a Single Service tutorial so that you do not have to repeat those steps.

  5. Download the MSF4J service from here and copy the JAR file to <EI_HOME>/wso2/msf4j/deployment/microservicesfolder. The back-end service is now deployed in the MSF4J profile of WSO2 EI.

Let's get started!

Setting up the message broker profile

The message broker profile (which is an instance of WSO2 Message Broker) is shipped with the WSO2 EI product distribution. You need to enable the following configurations to be able to store messages in the broker profile.

  1. Open the <EI_HOME>/conf/jndi.properties file and add the following line after the queue.MyQueue = example.MyQueue line:

    queue.PaymentRequestJMSMessageStore=PaymentRequestJMSMessageStore
  2. Copy the following JAR files from the <EI_HOME>/wso2/broker/client-lib/ directory to the <EI_HOME>/lib/ directory.

    • andes-client-3.2.13.jar

    • geronimo-jms_1.1_spec-1.1.0.wso2v1.jar

    • org.wso2.securevault-1.0.0-wso2v2.jar

Creating the Message Store

Now, let's create a message store artifact in EI Tooling. 

  1. Right click on SampleServices in the Project Explorer and navigate to New->Message Store.

  2. Select Create a new message-store artifact and fill in the information in the following table and click Finish.

    create new message store
    create new message store

    Click Finish.

Let's look at how we update the REST API with the Store mediator.

Creating the Deployable Artifacts

Let's now update the REST API so that the messages sent to SettlePaymentEP is forwarded to the message store we created above. 

  1. Drag and add a Store Mediator from the mediators palette just after the PayloadFactory mediator.

  2. With the Store mediator selected, access the Properties tab and fill in the information as in the following table:

    Let's use a PayloadFactory mediator to send a customized response message to the client. 

  3. Delete the Call mediator by right clicking on the mediator and selecting Delete from Model. Replace this with a PayloadFactory mediator from the Mediators palette to configure the response to be sent to the client. With the PayloadFactory mediator selected, access the Properties tab and fill in the information in the following table to define a customized message to be returned to the client.


    You should now have a completed configuration that looks like this:

Creating the Response Sequence

Let's create a Sequence that uses the message in the message store to send the request to SettlePaymentEP.

  1. Right click the SampleServices project in the Project Explorer and navigate to New -> Sequence. Select Create New Sequence and provide the name PaymentRequestProcessingSequence.


    Click Finish.

  2. Drag and drop a Call mediator from the Mediators palette and add SettlePaymentEP from Defined Endpoints palette to the empty box adjoining the Call mediator. This sends the request message from the store to SettlePaymentEP.

  3.  Drag and drop a Log mediator from the Mediators palette to log the response from SettlePaymentEP. Access the Properties tab and fill in the following information:

  4. Add a Drop mediator from the Mediators palette.

    You should now have a completed sequence configuration that looks like this:

Creating the Message Processor

Let's create a Message Sampling Processor to dispatch the request message from the message store to the PaymentRequestProcessingSequence.

You can also use the Scheduled Message Forwarding Processor here and define the endpoint within the processor. The Message Sampling Processor is used because you need to perform mediation on the request message in the next tutorial.

Right click the SampleServices project in the Project Explorer and navigate to  New -> Message Processor. Select create a new message-processor artifact and fill in the details as in the following table:

Field

Value

Description

Field

Value

Description

Message Processor Type

Select Message Sampling Processor

This processor takes the message from the store and puts it into a sequence.

Message Processor Name

PaymentRequestProcessor

The name of the scheduled message forwarding processor.

Message Store

Select PaymentRequestMessageStore

The message store from which the scheduled message forwarding processor consumes messages.

Processor State

Activate

Whether the processor needs to be activated or deactivated.

Sequence

Click Browse, click the workspace link, select PaymentRequestProcessingSequence and click OK.

The name of the sequence the message from the store needs to be sent to.