How to integrate WSO2 EI with RabbitMQ without passing credentials from address URI.

From this blog post, it is expected to explain how to publish messages to RabbitMQ queue by invoking a proxy service and especially without passing the username and password of RabbitMQ server within the proxy service.

Step 1

First RabbitMQ broker has to be installed. For that, I have followed [1] and executes “brew services start rabbitmq” in the terminal. Login to RabbitMQ Management UI using the below URL.

http://localhost:15672/

Step 2

Now queues can be created in RabbitMQ broker side. Refer to the attached screenshot for a queue “preview.outbound.01” in virtual host “preview.eai” which bound to “direct” type of exchange “preview.direct” and routing key “preview.entity.t0400145j5vr”.

Step 3

Then AMQP receiver and sender parameters in <EI_HOME>/conf/axis2/axis2.xml file have to be configured as below example and restart the EI server.

<transportReceiver name="rabbitmq" class="org.apache.axis2.transport.rabbitmq.RabbitMQListener">
<parameter name="AMQPConnectionFactory" locked="false">
<parameter name="rabbitmq.server.host.name" locked="false">localhost</parameter>
<parameter name="rabbitmq.server.port" locked="false">5672</parameter>
<parameter name="rabbitmq.server.user.name" locked="false">guest</parameter>
<parameter name="rabbitmq.server.password" locked="false">guest</parameter>
<parameter name="rabbitmq.connection.retry.interval" locked="false">10000</parameter>
<parameter name="rabbitmq.connection.retry.count" locked="false">-1</parameter>
<parameter name="rabbitmq.message.content.type">application/json</parameter>
</parameter>
</transportReceiver>
<transportSender name="rabbitmq" class="org.apache.axis2.transport.rabbitmq.RabbitMQSender">
<parameter name="CachedRabbitMQConnectionFactory" locked="false">
<parameter name="rabbitmq.server.host.name" locked="false">localhost</parameter>
<parameter name="rabbitmq.server.virtual.host" locked="false">preview.eai</parameter>
<parameter name="rabbitmq.server.port" locked="false">5672</parameter>
<parameter name="rabbitmq.server.user.name" locked="false">guest</parameter>
<parameter name="rabbitmq.server.password" locked="false">guest</parameter>
</parameter>
</transportSender>

Step 4

Refer to the below sample proxy service to send messages to RabbitMQ server.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="RMQPubliserTest_1"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
<log level="custom">
<property name="MessageFlow"
value="======= 1.0 RMQ TEST PUBLISHER 1 - Send to RMQ queue without username ======="/>
</log>
<send>
<endpoint>
<address uri="rabbitmq:/AMQPProxy?rabbitmq.connection.factory=CachedRabbitMQConnectionFactory&rabbitmq.exchange.name=preview.direct&rabbitmq.queue.routing.key=preview.entity.t0400145j5vr"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>

Please note that, when we properly configured sender parameters in axis2.xml (including the parameter “rabbitmq.server.virtual.host”), it is not mandatory to define the “rabbitmq.server.virtual.host” in the address URI of the proxy. Also, when we set “rabbitmq.exchange.type” and “rabbitmq.queue.durable” in RabbitMQ server side, it is not mandatory to define them in the address URI.

References

[1] https://www.rabbitmq.com/install-homebrew.html

[2] https://docs.wso2.com/display/EI640/RabbitMQ+AMQP+Transport