I have the following Java process which is listening to MyMessageQueue
queue of ActiveMQ.And I can see the message getting retrieved using this statement System.out.println("Message Retrieved is:" +message);
inside processBrokerQueues
method.
@Component
public class MessageConsumer {
@Autowired
private JavaMailSender javaMailSender;
// one instance, reuse
private final CloseableHttpClient httpClient = HttpClients.createDefault();
private static Connection connection;
// URL of the JMS server. DEFAULT_BROKER_URL will just mean that JMS server is on localhost
private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
private static String subject = "MyMessageQueue"; //Queue Name
// default broker URL is : tcp://localhost:61616"
private static ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
private static final Logger logger = LoggerFactory.getLogger(MessageConsumer.class);
private static final DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
// Working Code with JMS 2.0
@JmsListener(destination = "MyMessageQueue")
public void processBrokerQueues(String message) throws DaoException, JMSException {
System.out.println("Message Retrieved is:" + message);
}
private void createConnection() throws JMSException {
// Getting JMS connection from the server
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
connection = connectionFactory.createConnection();
}
private void close() throws IOException {
httpClient.close();
}
}
I am wondering, if I want to listen to 20-30 different queues, Is it the correct way to add multiple @JmsListener(destination = "MyMessageQueue")
with different queue names like MessageQueue1, MessageQueue2 .......
so on and so forth until MessageQueue30
?