[英]Unable to push message into ActiveMQ
I'm successfully pushing message into ActiveMQ from local Eclipse setup. 我已成功将消息从本地Eclipse安装程序推送到ActiveMQ中。 However, the same code does not push message when I try to execute from server as a
cron
job. 但是,当我尝试从服务器作为
cron
作业执行时,相同的代码不会推送消息。 It does not even throw an exception during code execution. 它甚至不会在代码执行期间引发异常。
Java environment - 1.8 Java环境-1.8
Supporting jars used: 使用的配套罐子:
Code: 码:
try {
map = getMessageDetails(session,"MessageQueueEmail");
userName = map.get("userName");
password = map.get("password");
hostName = map.get("mqHostName");
queue = map.get("queueName");
// Create a ConnectionFactory
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(userName, password, hostName);
// Create a Connection
connection = factory.createConnection();
// start the Connection
connection.start();
System.out.println("MQ started connection");
// Create a Session
sessionMQ = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination Queue
Destination destination = sessionMQ.createQueue(queue);
// Create a MessageProducer from the Session to the Queue
messageProducer = sessionMQ.createProducer(destination);
messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message
Message message = sessionMQ.createTextMessage(textMsg);
System.out.println("MQ Message sent successfully");
// Tell the producer to send the message
messageProducer.send(message);
} catch(Exception e) {
e.printStackTrace();
System.out.println("\n::::::::::::Error occurred sendEmailMessageToIntranet::::::::::::: " + e.getMessage());
}
Thanks everyone for response. 感谢大家的回应。 The issue is resolved after importing correct certificate file to the server.
将正确的证书文件导入服务器后,该问题得以解决。 Wondering, why MQ attempts failure notification had not logged
想知道为什么MQ尝试失败通知未记录
Your code looks ok except you might have expiration going. 您的代码看起来还可以,除非您可能要到期。 Try with PERSISTENT and most likely is the issues that you are not redirecting stderr in your cronjob ?
尝试使用PERSISTENT,很可能是您在cronjob中没有重定向stderr的问题? Make sure you do something like this:
确保您执行以下操作:
*/1 * * * * /something/send.sh &>> /something/out.log
* / 1 * * * * /something/send.sh &>> /something/out.log
And then check in the morning. 然后在早上检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.