ACTIVEMQ- publisher subscriber hello world example

前端 未结 4 823
北恋
北恋 2020-12-13 15:02

There are two programs: subscriber and publisher... Subscriber is able to put the message onto the topic and the message is sent successfully. When I check the activemq serv

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 15:30

    Your issue is that your consumer is running and then shutting down immediately.

    Try adding this into your consumer:

        consumer.setMessageListener(listner);
    
        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        connection.close();
    

    This will wait until you hit a key before stopping.

    Other things to consider:

    • Use a finally block for the close
    • Java naming conventions encourage using uppercase for the first letter of a class

提交回复
热议问题