|
ActiveMQ supports the Stomp Please see the Stomp site Enabling the ActiveMQ Broker for StompIts very easy to enable ActiveMQ for Stomp. Just add a connector to the broker using the stomp URL. <connector> <serverTransport uri="stomp://localhost:61626"/> </connector> Of course use any host name and port you like. If the above doesn't work, try the following which works with ServiceMix 3.0 + ActiveMQ 4.0.2: <transportConnectors> <transportConnector uri="stomp://localhost:61626"/> </transportConnectors> To see a full example, try this XML activemq xbean:foo.xml For more help see Run Broker. SecurityStomp implementation fully supports an ActiveMQ security mechanism. This means that the CONNECT command will return an ERROR frame on unsuccessful authentication. Also, the authorization policies will be applied when you try to access (read/write) certain destinations. If you use synchronous operations (by using receipts
Enabling Stomp over SSLIt's easy to configure ActiveMQ to use Stomp over SSL connection. All you have to do is use stomp+ssl transport prefix instead of stomp. For example, add the following transport configuration in your XML file <transportConnector name="stomp+ssl" uri="stomp+ssl://localhost:61612"/>
Working with Destinations with StompNote that the prefix in stomp /queue/ or /topic/ is removed from the string before passing it to ActiveMQ as a JMS destination. Also note that the default separator in MOM systems is . (DOT). So FOO.BAR is the normal syntax of a MOM queue - the Stomp equivalent would be /queue/FOO.BAR
Persistence of Stomp messagesBy default, Stomp produced messages are set to non-persistent. You have to explicitly tell your Stomp library to add "persistent:true" to all SEND requests, for any messages that you want to persist across ActiveMQ restarts. This is the opposite of the default for JMS submitted messages. Working with JMS Text/Bytes Messages and StompStomp is a very simple protocol - that's part of the beauty of it! As such, it does not have knowledge of JMS messages such as TextMessages or BytesMessages. The protocol does however support a content-length header. To provide more robust interaction between Stomp and JMS clients, ActiveMQ keys off of the inclusion of this header to determine what message type to create when sending from Stomp to JMS. The logic is simple:
This same logic can be followed when going from JMS to Stomp, as well. A Stomp client could be written to key off of the inclusion of the content-length header to determine what type of message structure to provide to the user. Message transformationsThe transformation message header on SEND and SUBSCRIBE messages could be used to instruct ActiveMQ to transform messages from text to the format of your desire. Currently, ActiveMQ comes with a transformer that can transform XML/JSON text to Java objects, but you can add your own transformers as well. Here's a quick example of how to use built-in transformer (taken from test cases) private String xmlText = "<org.apache.activemq.transport.stomp.SamplePojo>\n" + " <name>Dejan</name>\n" + " <city>Belgrade</city>\n" + "</org.apache.activemq.transport.stomp.SamplePojo>"; public void testTransformationReceiveXML() throws Exception { MessageProducer producer = session.createProducer(new ActiveMQQueue("USERS." + getQueueName())); ObjectMessage message = session.createObjectMessage(new SamplePojo("Dejan", "Belgrade")); message.setStringProperty("transformation", "jms-xml"); producer.send(message); String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL; stompConnection.sendFrame(frame); frame = stompConnection.receiveFrame(); assertTrue(frame.startsWith("CONNECTED")); frame = "SUBSCRIBE\n" + "destination:/queue/USERS." + getQueueName() + "\n" + "ack:auto" + "\n\n" + Stomp.NULL; stompConnection.sendFrame(frame); frame = stompConnection.receiveFrame(); assertTrue(frame.trim().endsWith(xmlText)); frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL; stompConnection.sendFrame(frame); }
In order to create your own transformer, you have to do the following:
For example the built-in transformer contains the following value class=org.apache.activemq.transport.stomp.XStreamFrameTranslator in the META-INF/services/org/apache/activemq/transport/frametranslator/jms-xml file. Stomp extensions for JMS message semanticsNote that Stomp is designed to be as simple as possible - so any scripting language / platform can message any other with minimal effort. Stomp allows pluggable headers on each request such as sending & receiving messages. ActiveMQ has several extensions to the Stomp protocol, so that JMS semantics can be supported by Stomp clients. An OpenWire JMS producer can send messages to a Stomp consumer, and a Stomp producer can send messages to an OpenWire JMS consumer. And Stomp to Stomp configurations, can use the richer JMS message control. Stomp supports the following standard JMS properties on SENT messages:
ActiveMQ extensions to StompYou can add custom headers to Stomp commands to configure the ActiveMQ protocol. Here are some examples:
|