If you have an application similar to the following then you can use Oracle Coherence as the JMS provider by using ezMQ APIs. The only change set the jndi.properties or the Context.PROVIDER_URL.
public class Client implements MessageListener {
public void someMethod () {
Properties env = new Properties();
env.setProperty(Context.PROVIDER_URL, "...");
InitialContext ctx = new InitialContext(env);
TopicConnectionFactory factory =
(TopicConnectionFactory) ctx.lookup("TopicConnectionFactory");
TopicConnection connection = factory.createTopicConnection();
Topic topic = (Topic) ctx.lookup("Topic");
addSubscriber(connection, topic);
publishMessage(connection, topic);
}
private void publishMessage(TopicConnection connection, Topic topic)
throws JMSException {
TopicSession pubSession =
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher publisher = pubSession.createPublisher(topic);
TextMessage message = pubSession.createTextMessage();
message.setText("Ashish");
publisher.publish(message);
}
private void addSubscriber(TopicConnection connection, Topic topic)
throws JMSException {
TopicSession subSession =
connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = subSession.createSubscriber(topic);
subscriber.setMessageListener(this);
}
public void onMessage(Message message) {
try {
TextMessage tMsg = (TextMessage) message;
String text = tMsg.getText();
System.out.println("On Message: " + text);
} catch (JMSException e) {
e.printStackTrace();
}
}
}This version of ezMQ is pretty basic and does not implement all the bells and whistles of other popular JMS providers but it works beautifully and provides a platform to expand. How is it implememted? There are two aspects of creating a JMS implementation:
- Taking care of JNDI
- Context (EzContext)
- Context Factory (EzContextFactory)
- Taking care of JMS
- Topic (EzTopic)
- TopicConnection (EzTopicConnection)
- TopicConnectionFactory (EzTopicConnectionFactory
- TopicSession (EzTopicSession)
- TopicPublisher (EzTopicPublisher)
- TopicSubscriber (EzTopicSubscriber)
- TextMessage (EzMessage)
No comments:
Post a Comment