diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java | 38 |
1 files changed, 38 insertions, 0 deletions
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 |
