import javax.jms.*;
import javax.naming.*;
public class JmsProducer {
public static void main(String[] args) throws NamingException, JMSException {
Context context = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("ConnectionFactory");
Destination destination = (Destination) context.lookup("queue/TestQueue");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage();
message.setText("Hello, JMS!");
producer.send(message);
connection.close();
}
}
import org.jboss.mq.*;
import org.jboss.mq.sm.*;
public class JBossMQProducer {
public static void main(String[] args) throws Exception {
MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setServerURL("localhost:1099");
MQQueueConnection connection = (MQQueueConnection) connectionFactory.createQueueConnection();
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueueSender sender = (MQQueueSender) session.createSender(session.getQueue("TestQueue"));
MQTextMessage message = (MQTextMessage) session.createTextMessage();
message.setText("Hello, JBossMQ!");
sender.send(message);
connection.close();
}
}