zeromq / jeromq-jms

JeroMQ JMS
25 stars 13 forks source link

`inproc` pub/sub appears to hang #13

Closed shs96c closed 5 years ago

shs96c commented 5 years ago

The example code below works if the topic is changed to use a tcp address but hangs indefinitely if an inproc address is used.

Could this be related in some way to https://github.com/zeromq/libzmq/issues/1257? It seems unlikely, but....

Note: as written, this example throws an exception on successful completion because of #12.

public class Jms {

  public static void main(String[] args) throws Exception {
    TopicConnectionFactory connectionFactory = new ZmqConnectionFactory();
    try (Connection connection = connectionFactory.createConnection()) {
      Session session = connection.createSession(false, AUTO_ACKNOWLEDGE);

      Topic sessionsTopic = session.createTopic("jms:topic:sessions?socket.addr=inproc://example");
//      Topic sessionsTopic = session.createTopic("jms:topic:sessions?socket.addr=tcp://localhost:1234");

      MessageProducer producer = session.createProducer(sessionsTopic);

      CountDownLatch latch = new CountDownLatch(1);
      MessageConsumer consumer = session.createConsumer(sessionsTopic);
      consumer.setMessageListener(message -> {
        try {
          System.out.println(((TextMessage) message).getText());
        } catch (JMSException e) {
          throw new RuntimeException(e);
        }
        latch.countDown();
      });

      TextMessage message = session.createTextMessage("Hello, World!");

      producer.send(sessionsTopic, message);

      latch.await();
    }
  }
}
shs96c commented 5 years ago

This looks related too: https://github.com/zeromq/jeromq/issues/289

mjeremym commented 5 years ago

This is an issue with the implementation. Each session gets a new Context instance. Create an inproc test without all the JMS wrapper I can duplicate the hanging by giving the sender and consumer sockets a different context.

I guess proving an option to re-user the context within the connection. Need to test.

regards Jeremy

mjeremym commented 5 years ago

Fixed with the release of version 3.0.1.