[英]activemq UDP jms connection
i work on a project with activemq java and i use ssl or udp connection .To receive messqge i use a QeueueReceiver and MessageListener Classes .the problem is that the ssl connection perfectly but when i choose a udp connection and i send 7 messages and i put the listener working i receive 5 messages after i receive only 2 messages . 我在使用activemq java的项目上工作,我使用ssl或udp连接。要接收messqge,我使用QeueueReceiver和MessageListener类。问题是ssl连接完美,但是当我选择udp连接并发送7条消息后我放在工作的侦听器中,我仅收到2条消息后收到5条消息。 i DONT know what exactly the problem sombedoy can help please there is a code
我不知道sombedoy可以帮助您解决什么问题,请输入代码
code ry { switch (protocol) { case "UDP": connectionFactoryUDP = new ActiveMQConnectionFactory(brokerUrlUDP); 代码ry {开关(协议){情况“ UDP”:connectionFactoryUDP =新的ActiveMQConnectionFactory(brokerUrlUDP); connection = connectionFactoryUDP.createQueueConnection(username, password);
连接= connectionFactoryUDP.createQueueConnection(用户名,密码);
break;
case "TLS":
connectionFactoryTLS = new ActiveMQSslConnectionFactory();
// create connection
connectionFactoryTLS.setBrokerURL(brokerUrlTLS);
connectionFactoryTLS.setTrustStore(trustStore);
connectionFactoryTLS.setTrustStorePassword(trustStorePassword);
connectionFactoryTLS.setKeyStore(keyStore);
connectionFactoryTLS.setKeyStorePassword(keyStorePassword);
connection = connectionFactoryTLS.createQueueConnection(username,password);
break;}
//ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.username, this.password, "tcp://localhost:61616");
// create connection
// start
connection.start();
// create session
// create queue (it will create if queue doesn't exist)
// create listener
System.out.println("____________________________________");
MessageListener messageListener = new MessageListener() {
@Override
public void onMessage(Message message) {
System.out.println("____________________________________");
// only text type message
if (message instanceof TextMessage) {
TextMessage txt = (TextMessage) message;
try {
System.out.println("Message received =---_________--" + txt.getText());
} catch (JMSException e) {
System.out.println("error retrieving message");
System.exit(1);
}
}
}
};
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(queueName);
QueueReceiver consumer = session.createReceiver(queue);
consumer.setMessageListener(messageListener);
System.in.read();
consumer.close();
session.close();
connection.close();
System.out.println("-----------closed----------");
log console 2015-10-16 18:30:42 DEBUG UdpTransport:382 - Binding to address: 0.0.0.0/0.0.0.0:0 2015-10-16 18:30:42 DEBUG Connection:1:55 - SENDING: ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:aymenmhidhi-PC-57832-1445013042216-1:1, clientId = ID:aymenmhidhi-PC-57832-1445013042216-0:1, clientIp = null, userName = aymenmhidhi, password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true, faultTolerant = false, failoverReconnect = false} 2015-10-16 18:30:42 DEBUG UdpTransport:124 - Sending oneway from: udp://localhost:61625?trace=true@49257 to target: localhost/127.0.0.1:61625 command: ConnectionInfo {commandId = 1, responseRequired = true, connectionId = ID:aymenmhidhi-PC-57832-1445013042216-1:1, clientId = ID:aymenmhidhi-PC-57832-1445013042216-0:1, clientIp = null, userName = aymenmhidhi, password = *****, brokerPath = null, brokerMasterConnector = false, manageable = true, clientMaster = true, faultTolerant = f 日志控制台2015-10-16 18:30:42 DEBUG UdpTransport:382-绑定到地址:0.0.0.0/0.0.0.0:0 2015-10-16 18:30:42 DEBUG Connection:1:55-SENDING:ConnectionInfo {commandId = 1,responseRequired = true,connectionId = ID:aymenmhidhi-PC-57832-1445013042216-1:1,clientId = ID:aymenmhidhi-PC-57832-1445013042216-0:1,clientIp = null,userName = aymenmhidhi,密码= *****,brokerPath = null,brokerMasterConnector =否,可管理= true,clientMaster = true,faultTolerant =否,failoverReconnect = false} 2015-10-16 18:30:42 DEBUG UdpTransport:124-从以下位置发送单向: udp:// localhost:61625?trace = true @ 49257到目标:localhost / 127.0.0.1:61625命令:ConnectionInfo {commandId = 1,responseRequired = true,connectionId = ID:aymenmhidhi-PC-57832-1445013042216-1:1 ,clientId = ID:aymenmhidhi-PC-57832-1445013042216-0:1,clientIp = null,userName = aymenmhidhi,password = *****,brokerPath = null,brokerMasterConnector = false,可管理= true,clientMaster = true,faultTolerant = f alse, failoverReconnect = false} 2015-10-16 18:30:42 DEBUG DefaultReplayBuffer:47 - Adding command ID: 1 to replay buffer: org.apache.activemq.transport.reliable.DefaultReplayBuffer@7e3e2cff object: java.nio.DirectByteBuffer[pos=129 lim=4096 cap=4096] 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:242 - Channel: udp://localhost:61625?trace=true@49257 sending datagram: 1 to: localhost/127.0.0.1:61625 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:110 - Channel: udp://localhost:61625?trace=true@49257 received from: Endpoint[name:/127.0.0.1:49258] about to process: Response {commandId = 1, responseRequired = false, correlationId = 1} 2015-10-16 18:30:42 DEBUG Connection:1:60 - RECEIVED: Response {commandId = 1, responseRequired = false, correlationId = 1} 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:110 - Channel: udp://localhost:61625?trace=true@49257 received from: Endpoint[name:/127.0.0.1:49258] about to process: ConnectionControl {commandId = 2, responseRequired = false, suspe
其他,failoverReconnect = false} 2015-10-16 18:30:42 DEBUG DefaultReplayBuffer:47-将命令ID:1添加到重播缓冲区:org.apache.activemq.transport.reliable.DefaultReplayBuffer@7e3e2cff对象:java.nio.DirectByteBuffer [pos = 129 lim = 4096 cap = 4096] 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:242-通道:udp:// localhost:61625?trace = true @ 49257发送数据报:1至:localhost / 127.0 .0.1:61625 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:110-频道:udp:// localhost:61625?trace = true @ 49257接收自:端点[名称:/127.0.0.1:49258]关于流程:响应{commandId = 1,requestRequired = false,correlationId = 1} 2015-10-16 18:30:42调试连接:1:60-接收到:响应{commandId = 1,responseRequired = false,correlationId = 1} 2015 -10-16 18:30:42 DEBUG CommandDatagramChannel:110-通道:udp:// localhost:61625?trace = true @ 49257接收自:要处理的端点[name:/127.0.0.1:49258]:ConnectionControl {commandId = 2,responseRequired =否,怀疑 nd = false, resume = false, close = false, exit = false, faultTolerant = false, connectedBrokers = , reconnectTo = , token = null, rebalanceConnection = false} 2015-10-16 18:30:42 DEBUG Connection:1:60 - RECEIVED: ConnectionControl {commandId = 2, responseRequired = false, suspend = false, resume = false, close = false, exit = false, faultTolerant = false, connectedBrokers = , reconnectTo = , token = null, rebalanceConnection = false} 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:110 - Channel: udp://localhost:61625?trace=true@49257 received from: Endpoint[name:/127.0.0.1:49258] about to process: BrokerInfo {commandId = 3, responseRequired = false, brokerId = ID:aymenmhidhi-PC-57133-1445011516433-0:1, brokerURL = tcp://aymenmhidhi-PC:61616, slaveBroker = false, masterBroker = false, faultTolerantConfiguration = false, networkConnection = false, duplexConnection = false, peerBrokerInfos = null, brokerName = localhost, connectionId = 0, brokerUploadUrl = null, networkProperties = null
nd =否,简历=否,关闭=否,退出=否,faultTolerant =否,connectedBrokers =,reconnectTo =,令牌= null,rebalanceConnection =否} 2015-10-16 18:30:42调试连接:1:60 -已接收:ConnectionControl {commandId = 2,responseRequired = false,suspend = false,resume = false,close = false,exit = false,faultTolerant = false,connectedBrokers =,reconnectTo =,token = null,rebalanceConnection = false} 2015-10 -16 18:30:42 DEBUG CommandDatagramChannel:110-通道:udp:// localhost:61625?trace = true @ 49257收到自:要处理的端点[name:/127.0.0.1:49258]:BrokerInfo {commandId = 3 ,responseRequired =否,brokerId = ID:aymenmhidhi-PC-57133-1445011516433-0:1,brokerURL = tcp:// aymenmhidhi-PC:61616,slaveBroker =否,masterBroker =否,faultTolerantConfiguration =否,networkConnection =否,duplexConnection =否,peerBrokerInfos =空,brokerName =本地主机,connectionId = 0,brokerUploadUrl =空,networkProperties =空 } 2015-10-16 18:30:42 DEBUG Connection:1:60 - RECEIVED: BrokerInfo {commandId = 3, responseRequired = false, brokerId = ID:aymenmhidhi-PC-57133-1445011516433-0:1, brokerURL = tcp://aymenmhidhi-PC:61616, slaveBroker = false, masterBroker = false, faultTolerantConfiguration = false, networkConnection = false, duplexConnection = false, peerBrokerInfos = null, brokerName = localhost, connectionId = 0, brokerUploadUrl = null, networkProperties = null} 2015-10-16 18:30:42 DEBUG Connection:1:55 - SENDING: ConsumerInfo {commandId = 2, responseRequired = true, consumerId = ID:aymenmhidhi-PC-57832-1445013042216-1:1:-1:1, destination = ActiveMQ.Advisory.TempQueue,ActiveMQ.Advisory.TempTopic, prefetchSize = 1000, maximumPendingMessageLimit = 0, browser = false, dispatchAsync = true, selector = null, clientId = null, subscriptionName = null, noLocal = true, exclusive = false, retroactive = false, priority = 0, brokerPath = null, optimizedAcknowledge = false, noRangeAcks = false, additionalPredicate
} 2015-10-16 18:30:42调试连接:1:60-收到:BrokerInfo {commandId = 3,responseRequired = false,brokerId = ID:aymenmhidhi-PC-57133-1445011516433-0:1,brokerURL = tcp: // aymenmhidhi-PC:61616,slaveBroker =否,masterBroker =否,faultTolerantConfiguration =否,networkConnection =否,duplexConnection =否,peerBrokerInfos =否,brokerName =本地主机,connectionId = 0,brokerUploadUrl =否,networkProperties =否} 2015- 10-16 18:30:42调试连接:1:55-发送:ConsumerInfo {commandId = 2,responseRequired = true,consumerId = ID:aymenmhidhi-PC-57832-1445013042216-1:1:-1:1,目标= ActiveMQ.Advisory.TempQueue,ActiveMQ.Advisory.TempTopic,prefetchSize = 1000,maximumPendingMessageLimit = 0,浏览器= false,dispatchAsync = true,选择器= null,clientId = null,subscriptionName = null,noLocal = true,排他= false,追溯= false,优先级= 0,brokerPath = null,optimizedAcknowledge = false,noRangeAcks = false,additionalPredicate = null} 2015-10-16 18:30:42 DEBUG UdpTransport:124 - Sending oneway from: udp://localhost:61625?trace=true@49257 to target: /127.0.0.1:49258 command: ConsumerInfo {commandId = 2, responseRequired = true, consumerId = ID:aymenmhidhi-PC-57832-1445013042216-1:1:-1:1, destination = ActiveMQ.Advisory.TempQueue,ActiveMQ.Advisory.TempTopic, prefetchSize = 1000, maximumPendingMessageLimit = 0, browser = false, dispatchAsync = true, selector = null, clientId = null, subscriptionName = null, noLocal = true, exclusive = false, retroactive = false, priority = 0, brokerPath = null, optimizedAcknowledge = false, noRangeAcks = false, additionalPredicate = null} 2015-10-16 18:30:42 DEBUG DefaultReplayBuffer:47 - Adding command ID: 2 to replay buffer: org.apache.activemq.transport.reliable.DefaultReplayBuffer@7e3e2cff object: java.nio.DirectByteBuffer[pos=155 lim=4096 cap=4096] 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:242 - Channel: udp://localhost:61625?trace=true@49257 sending datagram: 2 to
= null} 2015-10-16 18:30:42 DEBUG UdpTransport:124-从udp:// localhost:61625?trace = true @ 49257单向发送至目标:/127.0.0.1:49258命令:ConsumerInfo {commandId = 2,responseRequired = true,消费者ID = ID:aymenmhidhi-PC-57832-1445013042216-1:1:-1:1,目标= ActiveMQ.Advisory.TempQueue,ActiveMQ.Advisory.TempTopic,prefetchSize = 1000,maximumPendingMessageLimit = 0,浏览器=否,dispatchAsync =否,选择器=否,clientId =否,subscriptionName =否,noLocal =否,独占=否,追溯=否,优先级= 0,brokerPath =否,OptimizedAcknowledge =否,noRangeAcks =否,AdditionalPredicate = } 2015-10-16 18:30:42调试DefaultReplayBuffer:47-添加命令ID:2以重播缓冲区:org.apache.activemq.transport.reliable.DefaultReplayBuffer@7e3e2cff对象:java.nio.DirectByteBuffer [pos = 155 lim = 4096 cap = 4096] 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:242-频道:udp:// localhost:61625?trace = true @ 49257发送数据报:2至 : /127.0.0.1:49258 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:110 - Channel: udp://localhost:61625?trace=true@49257 received from: Endpoint[name:/127.0.0.1:49258] about to process: Response {commandId = 4, responseRequired = false, correlationId = 2} 2015-10-16 18:30:42 DEBUG Connection:1:60 - RECEIVED: Response {commandId = 4, responseRequired = false, correlationId = 2}
:/127.0.0.1:49258 2015-10-16 18:30:42 DEBUG CommandDatagramChannel:110-通道:udp:// localhost:61625?trace = true @ 49257接收自:端点[名称:/127.0.0.1:49258 ]即将处理:响应{commandId = 4,responseRequired = false,correlationId = 2} 2015-10-16 18:30:42调试连接:1:60-已接收:响应{commandId = 4,responseRequired = false,correlationId = 2}
brokerurl brokerUrlUDP=udp://localhost:61625?trace=true brokerurl brokerUrlUDP = udp:// localhost:61625?trace = true
Thanks. 谢谢。
package eu.dedalus.x1v1.arr.arrReceiver;
import java.util.concurrent.ThreadPoolExecutor;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQSslConnectionFactory;
import org.apache.activemq.broker.TransportConnector;
import org.apache.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
public class ActiveMQQueuListener {
private static final Logger log = Logger
.getLogger(ActiveMQQueuListener.class.getName());
private String brokerUrlTLS;
private String brokerUrlUDP;
private String username;
private String password;
private ArrListener listener;
private String queueName;
private String protocol;
private String keyStore;
private String trustStore;
private String keyStorePassword;
private String trustStorePassword;
private boolean exit = false;
private QueueConnection connection = null;
private QueueSession session = null;
private ActiveMQConnectionFactory connectionFactoryUDP;
private ActiveMQSslConnectionFactory connectionFactoryTLS;
private MessageConsumer consumer;
private ThreadPoolExecutor executor;
private TransportConnector connector;
public void startReceiving() throws Exception {
System.out.println("------Start receiving---------");
try {
switch (protocol) {
case "UDP":
connectionFactoryUDP = new ActiveMQConnectionFactory(
brokerUrlUDP);
connection = connectionFactoryUDP.createQueueConnection(
username, password);
break;
case "TLS":
connectionFactoryTLS = new ActiveMQSslConnectionFactory();
// create connection
connectionFactoryTLS.setBrokerURL(brokerUrlTLS);
connectionFactoryTLS.setTrustStore(trustStore);
connectionFactoryTLS.setTrustStorePassword(trustStorePassword);
connectionFactoryTLS.setKeyStore(keyStore);
connectionFactoryTLS.setKeyStorePassword(keyStorePassword);
connection = connectionFactoryTLS.createQueueConnection(
username, password);
break;
}
// ConnectionFactory connectionFactory = new
// ActiveMQConnectionFactory(this.username, this.password,
// "tcp://localhost:61616");
// create connection
// start
connection.start();
// create session
// create queue (it will create if queue doesn't exist)
// create listener
MessageListener messageListener = new MessageListener() {
@Override
public void onMessage(Message message) {
// only text type message
if (message instanceof TextMessage) {
TextMessage txt = (TextMessage) message;
try {
System.out
.println("Message received =---_________--"
+ txt.getText());
} catch (JMSException e) {
System.out.println("error retrieving message");
System.exit(1);
}
}
}
};
session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(queueName);
QueueReceiver consumer = session.createReceiver(queue);
consumer.setMessageListener(messageListener);
System.in.read();
consumer.close();
session.close();
connection.close();
System.out.println("-----------closed----------");
} catch (Exception e) {
System.out.println("Exception while sending message to the queue"
+ e);
throw e;
}
}
public void setListener(ArrListener listener) {
this.listener = listener;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public ArrListener getListener() {
return listener;
}
public static Logger getLog() {
return log;
}
public String getQueueName() {
return queueName;
}
public void setQueueName(String queueName) {
this.queueName = queueName;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getKeyStore() {
return keyStore;
}
public void setKeyStore(String keyStore) {
this.keyStore = keyStore;
}
public String getTrustStore() {
return trustStore;
}
public void setTrustStore(String trustStore) {
this.trustStore = trustStore;
}
public String getKeyStorePassword() {
return keyStorePassword;
}
public void setKeyStorePassword(String keyStorePassword) {
this.keyStorePassword = keyStorePassword;
}
public String getTrustStorePassword() {
return trustStorePassword;
}
public void setTrustStorePassword(String trustStorePassword) {
this.trustStorePassword = trustStorePassword;
}
public String getBrokerUrlTLS() {
return brokerUrlTLS;
}
public void setBrokerUrlTLS(String brokerUrlTLS) {
this.brokerUrlTLS = brokerUrlTLS;
}
public String getBrokerUrlUDP() {
return brokerUrlUDP;
}
public void setBrokerUrlUDP(String brokerUrlUDP) {
this.brokerUrlUDP = brokerUrlUDP;
}
public void exitMethod() {
System.exit(1);
try {
consumer.close();
session.close();
connection.close();
System.out.println("-----------closed----------");
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public boolean isExit() {
return exit;
}
public void setExit(boolean exit) {
this.exit = exit;
}
public Connection getConnection() {
return connection;
}
public ActiveMQConnectionFactory getConnectionFactoryUDP() {
return connectionFactoryUDP;
}
public void setConnectionFactoryUDP(
ActiveMQConnectionFactory connectionFactoryUDP) {
this.connectionFactoryUDP = connectionFactoryUDP;
}
public ActiveMQSslConnectionFactory getConnectionFactoryTLS() {
return connectionFactoryTLS;
}
public void setConnectionFactoryTLS(
ActiveMQSslConnectionFactory connectionFactoryTLS) {
this.connectionFactoryTLS = connectionFactoryTLS;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.