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 ESB artifacts:
Before you begin,
- Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
- 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. 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.Getting an error message? See the troubleshooting tips given under Installing Enterprise Integrator Tooling.
- 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.
- Download the MSF4J service from here and copy the JAR file to
<EI_HOME>/wso2/msf4j/deployment/microservices
folder. 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.
Open the <EI_HOME>/conf/jndi
and add the following line after the .properties
filequeue.MyQueue = example.MyQueue
line:
queue.PaymentRequestJMSMessageStore=PaymentRequestJMSMessageStore
Creating the Message Store
Now, let's create a message store artifact in EI Tooling.
- Right click on SampleServices in the Project Explorer and navigate to New->Message Store.
- Select Create a new message-store artifact and click Next.
Fill in the information in the following table.
Message Store Name PaymentRequestMessageStore Message Store Type Select WSO2 MB Message Store Queue Connection Factory amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5675'
Change the port to 5675.
JNDI Queue Name PaymentRequestJMSMessageStore 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.
- Click on the Sample Services project, click src → main → synapse-config → api and then double click the
HealthareAPI.xml
file. - Drag and add a Store Mediator from the mediators palette just after the PayloadFactory mediator.
With the Store mediator selected, access the Property tab and fill in the information as in the following table:
Field Value Available Message Store Select PaymentRequestMessageStore Message Store Double click to populate the value PaymentRequestMessageStore Description Payment Store Let's use a PayloadFactory mediator to send a customized response message to the client.
Delete the Call mediator adjoining the store 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 Property tab and fill in the information in the following table to define a customized message to be returned to the client.
Field Value Media Type Select json Payload Format Select 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.
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.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.
Drag and drop a Log mediator from the Mediators palette to log the response from SettlePaymentEP. Access the Property tab and fill in the following information:
Field Value Log Category Select INFO Log Level Select FULL 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 |
---|---|---|
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. |
Click Finish.
We have now finished creating all the required artifacts.
Packaging the artifacts
Since you created a message store, sequence and a message processor, these will need to be packaged into our existingCApp.
Package the C-App names SampleServicesCompositeApplication project with the artifacts created. Ensure the following artifact 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 runtime
Start the message broker profile as follows:
- Open a terminal and navigate to the
<EI_HOME>/bin
directory. Start the runtime by executing the message broker startup script as shown below.
sh broker.sh
The message broker profile is now ready to receive messages from the ESB profile.
Starting the MSF4J profile
To be able to send requests to the back-end service (which is an MSF4J service deployed in the MSF4J profile), you need to first start the MSF4J runtime:
- Open a terminal and navigate to the
<EI_HOME>/bin
directory. Start the runtime by executing the MSF4J startup script as shown below.
sh msf4j.sh
The Healthcare service is now active and you can start sending requests to the service.
Starting the ESB runtime and deploying the artifacts
On the Servers tab, expand the WSO2 Carbon server, right-click SampleServicesCompositeApplication, and choose Redeploy. The Console window will indicate that the CApp has been deployed successfully. If you do not have a server added in Eclipse, refer this tutorial. You can also deploy the artifacts to the ESB profile of WSO2 EI using a Composite Application Archive (CAR) file.
Sending requests to the ESB
Create a JSON file names
request.json
with the following request payload.{ "name": "John Doe", "dob": "1940-03-19", "ssn": "234-23-525", "address": "California", "phone": "8770586755", "email": "johndoe@gmail.com", "doctor": "thomas collins", "hospital": "grand oak community hospital", "cardNo": "7844481124110331" }
- Open a command line terminal and execute the following command from the location where
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 API resource QueryDoctorAPI.
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."}
Now check the ESB server Console in Eclipse and you will see that the response from SettlePaymentEP is logged 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.