Jms Sender code that sends message to JMS topic ( Weblogic ) + Linux
import javax.jms.*;
import javax.naming.*;
public class TopicPublisher {
public static void main(String[] args) throws Exception {
// Obtain a JNDI connection using the WebLogic JNDI provider
InitialContext context = new InitialContext();
// Look up the JMS topic
Topic topic = (Topic) context.lookup("jms/demoTopic");
// Look up a JMS connection factory
ConnectionFactory connectionFactory =
(ConnectionFactory) context.lookup("jms/DemoTopicConnectionFactory");
// Create a JMS connection
Connection connection = connectionFactory.createConnection();
// Create a JMS session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a JMS message producer
MessageProducer producer = session.createProducer(topic);
// Create a JMS text message
TextMessage message =
session.createTextMessage("Hello, JMS! This is a sample test message.");
// Send the message
producer.send(message);
System.out.println("\n----- JMS Message Sent Successfully! -----");
// Close the JMS resources
producer.close();
session.close();
connection.close();
}
}
#!/bin/bash
# Add WebLogic thin client to classpath
export CLASSPATH=$CLASSPATH:/opt/weblogic/wlserver/server/lib/wlthint3client.jar
# Run the JMS Topic Publisher
java \
-Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory \
-Djava.naming.provider.url=t3s://demo-jms-server.example.com:7004 \
-Djms.topic.jndiName=jms/demoTopic \
-Djms.connectionFactory.jndiName=jms/DemoTopicConnectionFactory \
-Dweblogic.security.SSL.ignoreHostnameVerification=true \
TopicPublisher
Thanks,
Srikanth Govada
Comments
Post a Comment