Java Publish via STOMP example

1,134 views
Skip to first unread message

Oi Lee

unread,
Nov 6, 2015, 2:20:59 PM11/6/15
to rabbitmq-users
Does anyone have any examples on how to set up and publish to a queue via STOMP written in Java? I googled around and came up with nothing.  Found examples for ActiveMQ, spring and some other ones but nothing for RabbitMQ. 

Thanks in advance.
Oi

Michael Klishin

unread,
Nov 6, 2015, 4:43:22 PM11/6/15
to rabbitm...@googlegroups.com, Oi Lee
On 6 November 2015 at 22:21:00, Oi Lee (lee...@gmail.com) wrote:
> Does anyone have any examples on how to set up and publish to a
> queue via STOMP written in Java?

Is your question about using RabbitMQ STOMP plugin with Java or do you need
to make STOMP interoperate with AMQP 0-9-1 or other protocol clients?

The former should be pretty much the same as with other STOMP servers. 
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Gary Russell

unread,
Nov 7, 2015, 12:01:03 PM11/7/15
to rabbitm...@googlegroups.com, Oi Lee
The Spring Framework has a Java Stomp Client [1] (since 4.2).

I just wrote a quick test and it works nicely with RabbitMQ:

@Test
public void test() throws Exception {
    Reactor2TcpStompClient stompClient = new Reactor2TcpStompClient("127.0.0.1", 61613);
    stompClient.setMessageConverter(new StringMessageConverter());
    final CountDownLatch latch = new CountDownLatch(1);
    StompSessionHandler handler = new StompSessionHandlerAdapter() {

        @Override
        public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
            session.send("/queue/stompQ", "foo");
            session.subscribe("/queue/stompQ", this);
        }

        @Override
        public void handleFrame(StompHeaders headers, Object payload) {
            System.out.println(payload);
            latch.countDown();
        }
    };
    stompClient.connect(handler);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    stompClient.shutdown();
}

Rabbit creates the queue in this case; see the rabbit docs about the stomp plugin [3].

For a higher-level abstraction, Spring Integration has channel adapters that sit on top of the Spring client [2].





--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send an email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oi Lee

unread,
Nov 13, 2015, 1:07:32 PM11/13/15
to rabbitmq-users, lee...@gmail.com
It's about using RabbitMQ STOMP plugin with Java. I couldn't find any examples, and it's very possible that it's because I am not searching correctly. All this MQ stuff is very new to me, so I don't even know how code it! =/

Thanks for all the help. :)
Oi

Oi Lee

unread,
Nov 13, 2015, 1:34:42 PM11/13/15
to rabbitmq-users, lee...@gmail.com
Actually let me clarify on my above answer. I couldn't find any RabbitMQ STOMP examples, but every time I search for Java STOMP examples, I get results for (mostly) ActiveMQ and Spring examples. 

I'm unsure if I can use these examples to code something for RabbitMQ. My ultimate goal is to be able to benchmark the different messaging protocols/services. So for STOMP, I need to use the STOMP plugin only (not STOMP Web plugin or AMPQ). 

Oi

Gary Russell

unread,
Nov 13, 2015, 1:39:52 PM11/13/15
to rabbitm...@googlegroups.com, Oi Lee
As I said, I tested the Spring STOMP Java client with the RabbitMQ plugin with no problems.

The code is in my earlier reply.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

Michael Klishin

unread,
Nov 13, 2015, 1:40:03 PM11/13/15
to rabbitm...@googlegroups.com, Oi Lee
On 13 November 2015 at 21:34:45, Oi Lee (lee...@gmail.com) wrote:
> I'm unsure if I can use these examples to code something for RabbitMQ.
> My ultimate goal is to be able to benchmark the different messaging
> protocols/services. So for STOMP, I need to use the STOMP plugin
> only (not STOMP Web plugin or AMPQ).

Using a STOMP client with ActiveMQ or RabbitMQ or any other server
should be nearly identical. There are certain broker-specific features
but key operations should work exactly the same way.
Reply all
Reply to author
Forward
0 new messages