I want to use embedded artemis MQ
I have one sender class and one listner tied to one queue.
import java.util.Date;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
public class AddRequestSender {
@Autowired
JmsTemplate testTemplate;
@Autowired
ActiveMQConnectionFactory jmsConnectionFactory;
private static final Logger LOGGER =
LoggerFactory.getLogger(AddRequestSender.class);
public AddRequestSender() {
}
public void sendMessages(String string) throws JMSException,
InterruptedException {
StringBuilder payload = null;
for (int i = 0; i < 5; ++i) {
payload = new StringBuilder();
payload.append("Message [").append(i).append("] sent at:
").append(new Date());
final String payload1= payload.toString();
final int j = i;
testTemplate.send("testQUeue",new MessageCreator() {
public Message createMessage(Session session) throws
JMSException {
//
TextMessage message = session.createTextMessage();
message.setText(payload1);
message.setIntProperty("messageCount", j);
return message;
}
});
}
}
}
My listener class
import java.util.concurrent.atomic.AtomicInteger;
import javax.jms.Message;
import javax.jms.MessageListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AddRequestQueueListener implements MessageListener {
AtomicInteger intx = new AtomicInteger();
private static final Logger LOGGER =
LoggerFactory.getLogger(AddRequestQueueListener.class);
@Override
public void onMessage(Message message) {
LOGGER.info("received testQUeue");
LOGGER.info("received intx"+intx.incrementAndGet());
}
}
When I am invoking sender.sendmessages only once,
I am getting output multiple times.
Below are logs.
2020-03-26 03:43:25,874 INFO [Thread-2
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d932270e-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d931d8eb-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d931d8eb-6ee5-11ea-ae52-340286d42c4f]], false, false, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@4536128,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:25,876 INFO [Thread-2
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d932752f-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d931d8eb-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d931d8eb-6ee5-11ea-ae52-340286d42c4f]], true, true, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@5daca19e,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:25,909 INFO [Thread-13
(ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl$6@165e389b)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601500: User anonymous is
sending a core message on target resource:
ServerSessionImpl(jms-session=*N/A*) [with parameters: [TransactionImpl
[xid=null, txID=249, xid=null, state=ACTIVE, createTime=1585174405876(Thu
Mar 26 03:43:25 IST 2020), timeoutSeconds=300, nr operations = 0]@32ba055b,
CoreMessage[messageID=0,durable=true,userID=d935f6a0-6ee5-11ea-ae52-340286d42c4f,priority=4,
timestamp=Thu Mar 26 03:43:25 IST 2020,expiration=0, durable=true,
address=testQUeue,size=351,properties=TypedProperties[messageCount=0,__AMQ_CID=d932270d-6ee5-11ea-ae52-340286d42c4f,_AMQ_ROUTING_TYPE=1]]@961604013,
false, false, RoutingContextImpl(Address=null, routingType=null,
PreviousAddress=null previousRoute:null, reusable=null, version=0)
..................................................
]]
2020-03-26 03:43:25,944 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received testQUeue
2020-03-26 03:43:25,945 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received intx1
2020-03-26 03:43:26,024 INFO [Thread-2
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d9493084-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d948bb51-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d948bb51-6ee5-11ea-ae52-340286d42c4f]], false, false, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@49bdaa27,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,025 INFO [Thread-2
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d9495795-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d948bb51-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d948bb51-6ee5-11ea-ae52-340286d42c4f]], true, true, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@45a39a80,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,028 INFO [Thread-12
(ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl$6@165e389b)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601500: User anonymous is
sending a core message on target resource:
ServerSessionImpl(jms-session=*N/A*) [with parameters: [TransactionImpl
[xid=null, txID=259, xid=null, state=ACTIVE, createTime=1585174406026(Thu
Mar 26 03:43:26 IST 2020), timeoutSeconds=300, nr operations = 0]@38a9ef30,
CoreMessage[messageID=0,durable=true,userID=d949a5b6-6ee5-11ea-ae52-340286d42c4f,priority=4,
timestamp=Thu Mar 26 03:43:26 IST 2020,expiration=0, durable=true,
address=testQUeue,size=351,properties=TypedProperties[messageCount=1,__AMQ_CID=d9490973-6ee5-11ea-ae52-340286d42c4f,_AMQ_ROUTING_TYPE=1]]@1016491261,
false, false, RoutingContextImpl(Address=null, routingType=null,
PreviousAddress=null previousRoute:null, reusable=null, version=0)
..................................................
]]
2020-03-26 03:43:26,032 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received testQUeue
2020-03-26 03:43:26,032 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received intx2
2020-03-26 03:43:26,056 INFO [Thread-2
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d94deb7a-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d94dc467-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d94dc467-6ee5-11ea-ae52-340286d42c4f]], false, false, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@6160fcab,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,058 INFO [Thread-2
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d94e399b-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d94dc467-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d94dc467-6ee5-11ea-ae52-340286d42c4f]], true, true, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@63a693b9,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,061 INFO [Thread-0
(ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl$6@165e389b)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601500: User anonymous is
sending a core message on target resource:
ServerSessionImpl(jms-session=*N/A*) [with parameters: [TransactionImpl
[xid=null, txID=269, xid=null, state=ACTIVE, createTime=1585174406058(Thu
Mar 26 03:43:26 IST 2020), timeoutSeconds=300, nr operations = 0]@14919b99,
CoreMessage[messageID=0,durable=true,userID=d94e87bc-6ee5-11ea-ae52-340286d42c4f,priority=4,
timestamp=Thu Mar 26 03:43:26 IST 2020,expiration=0, durable=true,
address=testQUeue,size=351,properties=TypedProperties[messageCount=2,__AMQ_CID=d94deb79-6ee5-11ea-ae52-340286d42c4f,_AMQ_ROUTING_TYPE=1]]@991804096,
false, false, RoutingContextImpl(Address=null, routingType=null,
PreviousAddress=null previousRoute:null, reusable=null, version=0)
..................................................
]]
2020-03-26 03:43:26,064 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received testQUeue
2020-03-26 03:43:26,065 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received intx3
2020-03-26 03:43:26,069 INFO [Thread-1
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d94fe750-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d94fc03d-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d94fc03d-6ee5-11ea-ae52-340286d42c4f]], false, false, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@48a89417,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,071 INFO [Thread-1
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d9503571-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d94fc03d-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d94fc03d-6ee5-11ea-ae52-340286d42c4f]], true, true, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@2f856ecd,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,074 INFO [Thread-6
(ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl$6@165e389b)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601500: User anonymous is
sending a core message on target resource:
ServerSessionImpl(jms-session=*N/A*) [with parameters: [TransactionImpl
[xid=null, txID=279, xid=null, state=ACTIVE, createTime=1585174406071(Thu
Mar 26 03:43:26 IST 2020), timeoutSeconds=300, nr operations = 0]@224c494e,
CoreMessage[messageID=0,durable=true,userID=d950aaa2-6ee5-11ea-ae52-340286d42c4f,priority=4,
timestamp=Thu Mar 26 03:43:26 IST 2020,expiration=0, durable=true,
address=testQUeue,size=351,properties=TypedProperties[messageCount=3,__AMQ_CID=d94fe74f-6ee5-11ea-ae52-340286d42c4f,_AMQ_ROUTING_TYPE=1]]@1238541389,
false, false, RoutingContextImpl(Address=null, routingType=null,
PreviousAddress=null previousRoute:null, reusable=null, version=0)
..................................................
]]
2020-03-26 03:43:26,078 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received testQUeue
2020-03-26 03:43:26,079 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received intx4
2020-03-26 03:43:26,083 INFO [Thread-1
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d9520a36-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d951e323-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d951e323-6ee5-11ea-ae52-340286d42c4f]], false, false, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@7784834c,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,085 INFO [Thread-1
(ActiveMQ-remoting-threads-ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f-1943275118)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601267: User anonymous is
creating a core session on target resource
ActiveMQServerImpl::serverUUID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f [with
parameters: [d9525857-6ee5-11ea-ae52-340286d42c4f, null, ****, 102400,
RemotingConnectionImpl [ID=d951e323-6ee5-11ea-ae52-340286d42c4f,
clientID=null, nodeID=ce49a3f9-6ee5-11ea-ae52-340286d42c4f,
transportConnection=InVMConnection [serverID=0,
id=d951e323-6ee5-11ea-ae52-340286d42c4f]], true, true, false, false, null,
org.apache.activemq.artemis.core.protocol.core.impl.CoreSessionCallback@52bdd19d,
true,
org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager$2@65259718,
anonymous]]
2020-03-26 03:43:26,090 INFO [Thread-12
(ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl$6@165e389b)]
org.apache.activemq.artemis.logs.AuditLogger: AMQ601500: User anonymous is
sending a core message on target resource:
ServerSessionImpl(jms-session=*N/A*) [with parameters: [TransactionImpl
[xid=null, txID=289, xid=null, state=ACTIVE, createTime=1585174406085(Thu
Mar 26 03:43:26 IST 2020), timeoutSeconds=300, nr operations = 0]@3f00d7db,
CoreMessage[messageID=0,durable=true,userID=d952f498-6ee5-11ea-ae52-340286d42c4f,priority=4,
timestamp=Thu Mar 26 03:43:26 IST 2020,expiration=0, durable=true,
address=testQUeue,size=351,properties=TypedProperties[messageCount=4,__AMQ_CID=d9520a35-6ee5-11ea-ae52-340286d42c4f,_AMQ_ROUTING_TYPE=1]]@1218936676,
false, false, RoutingContextImpl(Address=null, routingType=null,
PreviousAddress=null previousRoute:null, reusable=null, version=0)
..................................................
]]
2020-03-26 03:43:26,092 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received testQUeue
2020-03-26 03:43:26,093 INFO [Thread-0 (ActiveMQ-client-global-threads)]
com.adidas.enter.users.robot.jms.AddRequestQueueListener: received intx5
Thanks in advance,
Rudra
--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html