I'm glad that helped. At a quick glance your new code looks pretty good. The important thing was being able to only send the message to the "next" broker so that your broker filter doesn't get called in an infinite loop and your new code does this. Your new code is also much more efficient than before since you aren't trying to open up a new connection and session for each message.
-Chris On Tue, Jun 9, 2015 at 10:46 AM, Altounisi <mou7amm...@gmail.com> wrote: > Thank you very much christopher.l.shannon. > Your reply helped me to solve the problem. > This is the new code (the modifications are in bold) for any one who may be > interested. Your critics are welcomed of course. > > Regards, > > > public class MyBroker extends BrokerFilter { > public MyBroker(Broker next) { > super(next); > } > public void addConnection(ConnectionContext context, ConnectionInfo > info) throws Exception { > > > *sendNotification(context,"addConnection",info.getConnectionId().toString(),info.getClientId(),info.getClientIp());* > super.addConnection(context, info); > } > *public void sendNotification (ConnectionContext context,String > notificationType,String id,String clientId,String clientIp) throws > Exception > { > ActiveMQDestination destination = > > ActiveMQDestination.createDestination("monitoring.notifications",ActiveMQDestination.QUEUE_TYPE); > ActiveMQMapMessage msg = new ActiveMQMapMessage(); > msg.setString("notificationType",notificationType); > msg.setString("id",id); > msg.setString("clientId",clientId); > msg.setString("clientIp",clientIp); > msg.setPersistent(false); > msg.setTimestamp(System.currentTimeMillis()); > msg.setPriority((byte) javax.jms.Message.DEFAULT_PRIORITY); > msg.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE); > msg.setDestination(destination); > msg.setResponseRequired(false); > ProducerId producerId = new ProducerId("monitorNotifier"); > msg.setProducerId(producerId); > msg.setMessageId(new MessageId(producerId, > this.messageIdGenerator.getNextSequenceId())); > boolean originalFlowControl = context.isProducerFlowControl(); > final ProducerBrokerExchange producerExchange = new > ProducerBrokerExchange(); > producerExchange.setConnectionContext(context); > producerExchange.setMutable(true); > producerExchange.setProducerState(new ProducerState(new > ProducerInfo())); > try { > context.setProducerFlowControl(false); > this.next.send(producerExchange, msg); > } finally { > context.setProducerFlowControl(originalFlowControl); > } > }* > } > > > > > -- > View this message in context: > http://activemq.2283324.n4.nabble.com/put-a-message-in-queue-using-org-apache-activemq-broker-Broker-tp4697413p4697470.html > Sent from the ActiveMQ - User mailing list archive at Nabble.com. >