JMS新手 要求 - 连接到消息队列。尝试发送一些文件/消息来测试连接。
获取Error - 错误yarn.ApplicationMaster:用户类引发异常:java.io.IOException:无法绑定到服务器套接字:tcp://dbusmq-sd00007.svc.db.com:1427由于:java.net.BindException:无法分配请求的地址(绑定失败) java.io.IOException:无法绑定到服务器套接字:tcp://dbusmq-sd00007.svc.db.com:1427由于:java.net.BindException:无法分配请求的地址(绑定失败)
其防火墙/ SSL问题或代码有问题?
包裹练习;
import java.net.URI;
import java.net.URISyntaxException;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
public class jmsQueue {
public static void main(String[] args) throws URISyntaxException, Exception {
BrokerService broker = BrokerFactory.createBroker(new URI(
"broker:(tcp://dbusmq-sd00007.svc.db.com:1427)"));
broker.start();
Connection connection = null;
try {
// Producer
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"tcp://dbusmq-sd00007.svc.db.com:1427");
connection = connectionFactory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("QM.SU00007");
String payload = "Testing helloworld";
Message msg = session.createTextMessage(payload);
MessageProducer producer = session.createProducer(queue);
System.out.println("Sending text '" + payload + "'");
producer.send(msg);
// Consumer
/* MessageConsumer consumer = session.createConsumer(queue);
connection.start();
TextMessage textMsg = (TextMessage) consumer.receive();
System.out.println(textMsg);
System.out.println("Received: " + textMsg.getText());*/
session.close();
} finally {
if (connection != null) {
connection.close();
}
broker.stop();
}
}
}