Currently I have started to work on JMS Topic with ActiveMQ. I have created Publisher and Durable Subscribers through JAVA code (mentioned below) and I received the messages in subscribers side also.
Publisher.Java
public static void createConnectionAndSendMessage(String ipAddress)
{
try
{
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://"+ipAddress+":61617");
Connection connection = factory.createConnection();
connection.start();
Session topicSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = topicSession.createTopic("Test-Topic");
MessageProducer producer = topicSession.createProducer(topic);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
ObjectMessage message = topicSession.createObjectMessage();
TopicTO topicTO = new TopicTO();
topicTO.setId(i);
topicTO.setName("Sample");
message.setStringProperty("s_id", "Sample");
message.setObject((Serializable) topicTO);
producer.send(message);
System.out.println("message sent successfully");
}
}
catch(JMSException e)
{
System.out.println("error :" + e);
}
}
Subscriber.java
public void createConnectionAndReceiveMessage(String clientId, String ipAddress)
{
try
{
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://"+ipAddress+":61617");
Connection connection = connectionFactory.createConnection();
connection.setClientID(clientId);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("Test-Topic");
String selector = "s_id = 'Sample'";
System.out.println("selector : '"+selector+"'....");
TopicSubscriber consumer = session.createDurableSubscriber(topic, "Sub1", selector, true);
consumer.setMessageListener(new TopicMessageListener());
}
catch(Exception e)
{
System.out.println("error :" + e);
}
}
I have some doubts in Topic those are follows,
How may I check that how many subscribers actively looking for a message in Topic using Java JMS?
How can I get those active durable subscribers list from Topic?
Do we have any option to delete a posted message in Topic?
Help me in these contexts.
Thanks in advance.