This is the latest release in the 6.x.x family. For EI 7.0.0, click here.

All docs This doc
||
Skip to end of metadata
Go to start of metadata

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 to ensure guaranteed delivery of request messages. That is, messages never get lost because they are stored in the message store and thereby 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 descriptions of the concepts that you need to know when creating ESB artifacts:

Before you begin,

  • Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:
    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.6.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.6.0\
    Ubuntu/usr/lib/wso2/EnterpriseIntegrator/6.6.0
    CentOS/usr/lib64/EnterpriseIntegrator/6.6.0
  • Select the relevant WSO2 Integration Studio based on your operating system and download it from here.
    The path to this folder is referred to as <EI_TOOLING> throughout this tutorial.

    Getting an error message? See the troubleshooting tips given under Installing WSO2 Integration Studio.

  • If you did not try the Exposing Several Services as a Single Service tutorial yet,
    1. Download the pre-packaged project that contains the configurations of the Exposing Several Services as a Single Service tutorial.
    2. Open WSO2 Integration Studio, click File, and click Import.
    3. Next, expand the WSO2 category and select Existing WSO2 Projects into workspace, click Next, and upload the project file.

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 6.6.0 product distribution. You need to enable the following configurations in the ESB to be able to store messages in the Broker profile.

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

queue.PaymentRequestJMSMessageStore=PaymentRequestJMSMessageStore

Creating the Message Store

Now, let's create a message store artifact in WSO2 Integration Studio. 

  1. Right-click SampleServices in the project explorer and navigate to New->Message Store.
  2. Select Create a new message-store artifact, click Next, fill in the information in the following table, and click Finish.

    Message Store NamePaymentRequestMessageStore
    Message Store TypeSelect WSO2 MB Message Store
    Queue Connection Factory

    amqp://admin:[email protected]/carbon?brokerlist='tcp://localhost:5675'

    Change the port to 5675.

    JNDI Queue NamePaymentRequestJMSMessageStore

  3. Click Finish.

Let's update the REST API.

Updating the REST API

Let's 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 Property tab and fill in the information as in the following table:

    FieldValue
    Available Message StoreSelect PaymentRequestMessageStore
    Message StoreSelect PaymentRequestMessageStore
    DescriptionPayment Store

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

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

    FieldValue
    Media TypeSelect json
    Payload FormatSelect Inline
    Payload{"message":" Payment request successfully submitted. Payment confirmation will be sent via email ."}

    To avoid getting an error message, first select Media Type before selecting Payload.

    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, click Next, and give PaymentRequestProcessingSequence as the sequence name.

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

  4.  Drag and drop a Log mediator from the Mediators palette next to the Call mediator. This logs the response from SettlePaymentEP. Access the Property tab and fill in the following information:

    FieldValue
    Log CategorySelect INFO
    Log LevelSelect FULL
  5. Add a Drop mediator from the Mediators palette to end of the sequence.  You should now have a completed sequence configuration that looks like this:

  6. Save the updated REST API configuration.

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 SampleServices in the project explorer and navigate to  New -> Message Processor. Select Create a new message-processor artifact, click Next, and fill in the following details:

FieldValueDescription
Message Processor TypeSelect Message Sampling Processor

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

Message Processor NamePaymentRequestProcessorThe name of the scheduled message forwarding processor.
Message StoreSelect PaymentRequestMessageStoreThe message store from which the scheduled message forwarding processor consumes messages.
Processor StateActivateWhether the processor needs to be activated or deactivated.
Sequence

Follow the steps given below:

  1. Click Browse.
  2. Click the workspace link.
  3. Click Carbon Application Sequences > SampleServices.
  4. Select PaymentRequestProcessingSequence and click OK.
The name of the sequence to which the message (from the store) needs to be sent.

Click Finish.

We have now finished creating all the required artifacts.

Packaging the artifacts

Package the artifacts you created above in the SampleServicesCompositeApplication project: 

  1. Open the pom.xml file of the SampleServicesCompositeApplication project, which is already included in the project explorer.
  2. Select the artifact that needs to be included into the CAR file.

Ensure that the following check boxes are selected in the Composite Application Project POM Editor.

  • SampleServices
    • HealthcareAPI
    • ClemencyEP
    • GrandOakEP
    • PineValleyEP
    • ChannelingFeeEP
    • SettlePaymentEP
    • PaymentRequestMessageStore
    • PaymentRequestProcessingSequence
    • PaymentRequestProcessor
  • SampleServicesRegistry

Starting the Message Broker profile

Start the Message Broker profile as follows:

Open a terminal and execute the following command:

sudo wso2ei-6.6.0-broker

Go to Start Menu -> Programs -> WSO2 -> Enterprise Integrator 6.6.0 Broker. This will open a terminal and start the Message Broker profile.

The Message Broker profile is now ready to receive messages from the ESB profile.

Starting the ESB profile and deploying the artifacts

If you do not already have an ESB server added to WSO2 Integration Studio, follow the instructions in a previous tutorial.

If you have already added the ESB profile server and deployed SampleServicesCompositeApplication (in a previous tutorial):

  1. Go to the Servers tab and click  to start the server. 
  2. Right-click SampleServicesCompositeApplication and click Redeploy as shown below.

The server Console will indicate that the CApp has been redeployed successfully.

Starting the back-end service

Download and start the back-end service that will process appointment requests:

  1. Download the JAR file of the back-end service.
  2. Open a terminal and navigate to the location where your saved the back-end service.

  3. Execute the following command to start the service:

    java -jar Hospital-Service-JDK11-2.0.0.jar

The Healthcare service is now active and you can start sending requests to the service.

Sending requests to the ESB profile

  1. Create a JSON file named request.json with the following request payload:

    {
    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "[email protected]",
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "cardNo": "7844481124110331"
    }
  2. Open a command line terminal and execute the following command from the location where the request.json file you created is saved:

    curl -v -X POST --data @request.json http://localhost:8280/healthcare/categories/surgery/reserve --header "Content-Type:application/json"

    This is from the URI-Template defined when creating the QueryDoctorAPI API resource.

    http://<host>:<port>/categories/{category}/reserve

    You will see the response as follows:

    {"message":"Payment request successfully submitted. Payment confirmation will be sent via email."}
  3. See that the response from SettlePaymentEP is logged in the Console as follows:

    [2017-04-30 14:33:48,578] [EI-Core]  INFO - LogMediator message = Routing to grand oak community hospital
    
    [2017-04-30 14:33:48,598] [EI-Core]  INFO - TimeoutHandler This engine will expire all callbacks after GLOBAL_TIMEOUT: 120 seconds, irrespective of the timeout action, after the specified or optional timeout
    
    [2017-04-30 14:33:53,464] [EI-Core]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:a2cf1fd2-7a89-44b6-9571-990bbdfbd289, Direction: request, Payload: {"appointmentNo":1,"doctorName":"thomas collins","patient":"John Doe","actualFee":7000.0,"discount":20,"discounted":5600.0,"paymentID":"a77038e9-3e42-46f7-ac97-11e1b3a50018","status":"Settled"}

You have now explored how the ESB profile of WSO2 EI can be used to implement store and forward messaging using Message Stores, Message Processors, and the Store mediator.

  • No labels