Return-Path: X-Original-To: apmail-activemq-users-archive@www.apache.org Delivered-To: apmail-activemq-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 787531860A for ; Tue, 9 Jun 2015 16:47:57 +0000 (UTC) Received: (qmail 58150 invoked by uid 500); 9 Jun 2015 16:47:57 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 58107 invoked by uid 500); 9 Jun 2015 16:47:57 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 58089 invoked by uid 99); 9 Jun 2015 16:47:56 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jun 2015 16:47:56 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 6FC951A48BD for ; Tue, 9 Jun 2015 16:47:56 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 5.385 X-Spam-Level: ***** X-Spam-Status: No, score=5.385 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, URIBL_BLOCKED=0.001, URI_HEX=1.313, URI_TRY_3LD=1.171] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id YUCh6lnPVrZG for ; Tue, 9 Jun 2015 16:47:41 +0000 (UTC) Received: from mail-pd0-f177.google.com (mail-pd0-f177.google.com [209.85.192.177]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 505872315E for ; Tue, 9 Jun 2015 16:47:40 +0000 (UTC) Received: by pdjn11 with SMTP id n11so18850542pdj.0 for ; Tue, 09 Jun 2015 09:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=R01wbDdVHeJv150+SA10AP86rRUPI6WCO/0t56pqEDs=; b=d4v0fhQhK3+KKdfh+09DgUj3P3mPlOK5fpm4N9hyx49fIdlMxwQeE6ste3AvsBk1L7 PvNBCJFuoHzUwBD5Y9KkOOWldeVnbbBBkZVpidv3UaT2U3bQelOUwDwoqoq4Sh2JfNVo cLBGv2NnKi8piQLmVPkPwDWhs5V2T4s2FV1/aRzFPX1YXZmLSH8dwuRDYFbI44J2qDq3 ZPzJLEOasKtvRL7y8qlrbrYHOYXBcRHe9U0v3w4KROdbPACJcGmRIFnK23P9hiUODWUJ 6dBSavKkspw104bmRDKoWtjnfr/s9Fyb9LUZkb8aQizaVzQre2s4oq4IxUZ4L0gIzcdm OP4g== X-Received: by 10.68.68.203 with SMTP id y11mr40282890pbt.34.1433868413832; Tue, 09 Jun 2015 09:46:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.70.43.106 with HTTP; Tue, 9 Jun 2015 09:46:23 -0700 (PDT) In-Reply-To: <1433861206061-4697470.post@n4.nabble.com> References: <1433778551249-4697413.post@n4.nabble.com> <1433861206061-4697470.post@n4.nabble.com> From: Christopher Shannon Date: Tue, 9 Jun 2015 12:46:23 -0400 Message-ID: Subject: Re: put a message in queue using org.apache.activemq.broker.Broker To: users@activemq.apache.org Content-Type: multipart/alternative; boundary=001a1138053e7616e80518188178 --001a1138053e7616e80518188178 Content-Type: text/plain; charset=UTF-8 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 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. > --001a1138053e7616e80518188178--