From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../src/examples/messaging/LogClient.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java new file mode 100644 index 0000000..483c0f1 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java @@ -0,0 +1,38 @@ +package examples.messaging; + +import javax.jms.*; +import javax.naming.InitialContext; + +public class LogClient { + + public static void main(String[] args) throws Exception { + // Initialize JNDI + InitialContext ctx = new InitialContext(System.getProperties()); + + // 1: Lookup connection factory + TopicConnectionFactory factory = + (TopicConnectionFactory) ctx.lookup("jms/TopicConnectionFactory"); + + // 2: Use connection factory to create JMS connection + TopicConnection connection = factory.createTopicConnection(); + + // 3: Use connection to create a session + TopicSession session = + connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); + + // 4: Lookup destination + Topic topic = (Topic)ctx.lookup("jms/Topic"); + + // 5: Create a message publisher + TopicPublisher publisher = session.createPublisher(topic); + + // 6: Create and publish a message + TextMessage msg = session.createTextMessage(); + msg.setText("This is a test message."); + publisher.send(msg); + + // finish + publisher.close(); + System.out.println("Message published. Please check application server's console to see the response from MDB."); + } +} \ No newline at end of file -- cgit v1.2.3