Wednesday, July 20, 2016

Activemq REST API adapter for external systems

Following content is tested only with Apache ActiveMQ 5.13.3

If we need to implement a communication between a ActiveMQ JMS server and any REST support external system that is implemented with a technology which has no JMS API support, ActiveMQ REST API comes as a solution. So, this REST API can be introduced as an adapter for any External system to be connected with a ActiveMQ JMS server.

ActiveMQ REST API provides following services.
1. Publish a message.
2. Consume a message.
3. Get list of queues.
4. Get list of messages in a particular queue or topic.
5. Get the content of a particular message.

Publish a message

Method : POST
URI format :
http://localhost:8161/api/message/queue_or_topic_name?type=either_queue_or_topic&requestTimeout=time_in_miliseconds&body=message to send&clientId=any_unique_id_for_client
Example URI:
http://localhost:8161/api/message/FOO?type=queue&requestTimeout=1000&body=This is test 34&clientId=soapui

Consume a message

Method :GET
URI format :
http://localhost:8161/api/message/queue_or_topic_name?type=either_queue_or_topic&clientId=any_unique_id_for_client&requestTimeout=time_in_miliseconds
Example URI:
http://localhost:8161/api/message/FOO?type=queue&clientId=soapui&requestTimeout=1000

Get list of queues or topics

Method :GET
URI format :
http://localhost:8161/admin/xml/queues.jsp

Get list of messages in a particular queue or topic

Method :GET
URI format :
http://localhost:8161/admin/queueBrowse/queue_or_topic_name
Example URI:
http://localhost:8161/admin/queueBrowse/FOO 

Get the content of a particular message

Method :GET
URI format :
http://localhost:8161/admin/queueBrowse/queue_or_topic_name?msgId=ID_value_of_a_particular_message_in_mentioned_queue_or_topic
Example URI:
http://localhost:8161/admin/queueBrowse/FOO?msgId=ID:dhcppc1-54766-1469009393902-5:1:1:1:4


NOTE:

If the authentication is enabled in the ActiveMQ admin as example in jetty.xml

 <bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint">
        <property name="name" value="BASIC" />
        <property name="roles" value="user,admin" />
        <!-- set authenticate=false to disable login -->
        <property name="authenticate" value="true" />
    </bean>



we have to set security headers. If not 401 response will be received. So, following header should be set in the REST request

Authorization: Basic YWRtaW46YWRtaW4= 

YWRtaW46YWRtaW4= equivalent to the base 64 encoded version of the provided_username:provided_password
(Username and password is one of set which you use to access to the ActiveMq webconsole.)




No comments:

Post a Comment