Publishing Messages To Message Broker Using Event Mediator
By Shammi Jayasinghe
- 12 Jun, 2012
We are using WSO2 Enterprise Service Bus 4.0.3 and WSO2 Message Broker 1.0.2 to implement this scenario. Once you have these two products, extract them. I am referring ESB_HOME to the extracted folder of the wso2esb and MB_HOME to the extracted folder of the wso2mb.
|WSO2 Enterprise Service Bus||4.0.3|
|WSO2 Message Broker||1.0.2|
1. Changing the configuration of WSO2 Message Broker to run on https port 9444 and http port 9764.
- For this you need to change the offset value to "1" in the carbon.xml file of Message Broker product which can be found in the location MB_HOME/repository/conf
<!-- Ports offset. This entry will set the value of the ports defined below to the define value + Offset. e.g. Offset=2 and HTTPS port=9443 will set the effective HTTPS port to 9445 --> <Offset>1</Offset>
once you done the above configuration, you can start wso2 Message Broker.
2. Change the configuration of WSO2 ESB to use WSO2MB as Remote Delivery Manager.
- For this you need to edit the file event-broker.xml which is located at ESB_HOME/repository/cont folder.
Step01: Comment out the inmemory delivery manager configurations as :
<!--<deliveryManager name="deliveryManager" class="org.wso2.carbon.event.core.internal.delivery.inmemory.InMemoryDeliveryManagerFactory"> <minSpareThreads>25</minSpareThreads> <maxThreads>150</maxThreads> <maxQueuedRequests>100</maxQueuedRequests> <keepAliveTime>1000</keepAliveTime> <topicStoragePath>event/topics</topicStoragePath> <matchingManager name="matchingManager" class="org.wso2.carbon.event.core.internal.delivery.inmemory.InMemoryMatchingManagerFactory"/> </deliveryManager> -->
Step 02: Uncomment the JMS Delivery manager and change the entries as : (Please pay attention to the entries in Bold)
<deliveryManager name="deliveryManager" class="org.wso2.carbon.event.core.internal.delivery.jms.QpidJMSDeliveryManagerFactory" type="remote"> <remoteMessageBroker> <hostName>localhost</hostName> <servicePort>9444</servicePort> <webContext>/</webContext> <userName>admin</userName> <password>admin</password> <qpidPort>5673</qpidPort> <clientID>clientID</clientID> <virtualHostName>carbon</virtualHostName> </remoteMessageBroker> </deliveryManager>
Done ...!!! Now you can start wso2 esb and send messages from ESB to MB.
"We need to publish a message to a topic in WSO2 ESB via the event mediator from an esb proxy and that message need to be stored in a message box of WSO2 Message Broker"
Message Flow is like bellow;
Incoming Message > ESB Proxy > Event Mediator > Topic in ESB > Topic in MB > Message Box in MB
Message broker preparations: For this you need to create a MessageBox and a Topic in wso2 message broker and create a subscription to that topic which is pointing to the message box.
Step 01 : Create a message box called "foo" in wso2 message broker with visibility time out 100.
Step 02: Create a topic called "bar" in message broker
Step 03: Create a subscription to the created topic
Step 04: Subscribe to the topic with providing the event sink url as "sqs://admin/foo"
Now you have completed the message broker preparations
In ESB also , you need to create a topic with the same name of the topic that we created in the message broker. In our scenario it is "bar"
Please be noted that you do not need to create any subscription in ESB for this topic. The only thing required is to use the same name for the topic.
Now you can create a proxy service in ESB and use the event mediator in that proxy to publish a message to the topic in ESB. That message will be stored in the message box in Message Broker.
Sample proxy in ESB to publish a message to the topic "bar".
<proxy name="Message_Broker_Invoking_proxy" transports="https http" startOnLoad="true" trace="disable">
Shammi Jayasinghe, Senior Software Engineer, WSO2 Inc.