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 36BA7E479 for ; Tue, 26 Feb 2013 05:38:28 +0000 (UTC) Received: (qmail 67686 invoked by uid 500); 26 Feb 2013 05:38:27 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 67469 invoked by uid 500); 26 Feb 2013 05:38:27 -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 67431 invoked by uid 99); 26 Feb 2013 05:38:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Feb 2013 05:38:25 +0000 X-ASF-Spam-Status: No, hits=-3.7 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [81.252.56.12] (HELO airbus-sf4.airbus.gmessaging.net) (81.252.56.12) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Feb 2013 05:38:17 +0000 Received: from airbus-sf4.airbus.gmessaging.net (localhost.localdomain [127.0.0.1]) by localhost.airbus.gmessaging.net (Postfix) with SMTP id A236A164C38D; Tue, 26 Feb 2013 06:37:56 +0100 (CET) Received: from de0-mailhub-p12.res.airbus.corp (unknown [44.225.3.154]) by airbus-sf4.airbus.gmessaging.net (Postfix) with ESMTP id 58DF8164C37D; Tue, 26 Feb 2013 06:37:56 +0100 (CET) Received: from DE0-MAILMBX-P21.res.airbus.corp ([44.225.3.150]) by de0-mailhub-p12.res.airbus.corp ([44.225.3.154]) with mapi; Tue, 26 Feb 2013 06:37:56 +0100 From: "AMARNATH, Balachandar" To: "users@activemq.apache.org" CC: "ted_shear@yahoo.com" Date: Tue, 26 Feb 2013 06:37:54 +0100 Subject: RE: Conntecting to a remote broker. Thread-Topic: Conntecting to a remote broker. Thread-Index: Ac4Tsj5A0q454BNzQWi4FcK/0AF80wAMOa2Q Message-ID: <9131_1361857076_512C4A34_9131_6769_1_E6472BD072676843ADB8D37E50F4C88D0BED39D7AA@DE0-MAILMBX-P21.res.airbus.corp> References: <1361823897277-4664053.post@n4.nabble.com> <25580_1361835950_512BF7AD_25580_16670_1_CAKS7T5OJ++zJOvzgjtQjHvq-vgkT-3snGovU0jq3hkC9WV=ywA@mail.gmail.com> In-Reply-To: <25580_1361835950_512BF7AD_25580_16670_1_CAKS7T5OJ++zJOvzgjtQjHvq-vgkT-3snGovU0jq3hkC9WV=ywA@mail.gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org HelloWorldConsumer.java ************************** import java.util.ArrayList; import javax.jms.Connection; import javax.jms.Destination; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; public class HelloWorldConsumer { =09 //public void run() { public static void main(String[] args ){ try { String url =3D ActiveMQConnection.DEFAULT_BROKER_URL; =20=20=09=09=09=09 ActiveMQConnectionFactory connectionFactory =3D new ActiveM= QConnectionFactory(url); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 // Create a Connection Connection connection =3D connectionFactory.createConnectio= n(); connection.start(); // Create a Session Session session =3D connection.createSession(false, Session= .AUTO_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination =3D session.createQueue("TEST.FOO"); // Create a MessageConsumer from the Session to the Topic o= r Queue MessageConsumer consumer =3D session.createConsumer(destina= tion); // Wait for a message =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ArrayList contents =3D new ArrayList(); boolean flag =3D true; =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 while (flag){ Message message =3D consumer.receive(1000); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=09 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 if (message instanceof TextMessage) { TextMessage textMessage =3D (TextMessage) message; String text =3D textMessage.getText(); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 System.out.println("Received : " + text + " and process= ing"); //Thread.sleep(1500);=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 if (text.equalsIgnoreCase("END")){ System.out.println("The recvd text is "+text);=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 flag =3D false; } contents.add(text); } else {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=09 System.out.println("Received : "+message);=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20 }=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 }=20=20=20 System.out.println("Exiting.."); System.out.println("The contents collected in consumer.java= is "+contents.size()); connection.close(); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 } catch (Exception e) { System.out.println("Caught: " + e); e.printStackTrace(); } }=09 } HelloWorldProducer.java ************************** import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.Destination; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; public class HelloWorldProducer { =09 public static void main(String[] args) throws Exception { =09=09 String url =3D ActiveMQConnection.DEFAULT_BROKER_URL; =20=20=20=20=20=20=09=09=09=09 ActiveMQConnectionFactory connectionFactory =3D new ActiveM= QConnectionFactory(url); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 // Create a Connection Connection connection =3D connectionFactory.createConnectio= n(); connection.start(); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 // Create a Session Session session =3D connection.createSession(false,Session.= AUTO_ACKNOWLEDGE); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 // Create the destination (Topic or Queue) Destination destination =3D session.createQueue("TEST.FOO"); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 // Create a MessageProducer from the Session to the Topic o= r Queue MessageProducer producer =3D session.createProducer(destina= tion); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 int counter =3D 0; boolean flag =3D true;=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 while (counter < 50) { =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=09 counter++; String text =3D "Message "+counter;// + Thread.currentThrea= d().getName() + " : " + this.hashCode(); TextMessage message =3D session.createTextMessage(text);=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 // Tell the producer to send the message =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 producer.send(message);=20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 System.out.println("Sent message '" + message.getText() + "= '"); Thread.sleep(1000); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 } Thread.sleep(2000); producer.send(session.createTextMessage("END")); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Thread.sleep(4000); producer.send(session.createTextMessage("END")); // Clean up=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 connection.close(); =20=20=20=20=20=20=20=20 } } Hope this helps :-) With regards Bala -----Original Message----- From: Christian Posta [mailto:christian.posta@gmail.com]=20 Sent: 26 February 2013 05:15 To: users@activemq.apache.org Subject: Re: Conntecting to a remote broker. A few seconds on google turns up this excellent blog post that perfectly answers your question: http://www.javablogging.com/simple-guide-to-java-message-service-jms-using-= activemq/ Follow it step by step and you'll be on your way. Cheers On Mon, Feb 25, 2013 at 1:24 PM, iluv2salsa wrote: > I am in need of a simple example to do the following: > On one Fedora 18 machine create a broker and a consumer to recieve a > message. > On another Fedora 18 machine create a producer and send a message. > > i have been trying for a couple of weeks and spend many hours on google. > > Please, nothing fancy, no jboss, glassfish, etc. > > > > > -- > View this message in context: > http://activemq.2283324.n4.nabble.com/Conntecting-to-a-remote-broker-tp46= 64053.html > Sent from the ActiveMQ - User mailing list archive at Nabble.com. > --=20 *Christian Posta* http://www.christianposta.com/blog twitter: @christianposta This mail has originated outside your organization, either from an external= partner or the Global Internet. Keep this in mind if you answer this message. The information in this e-mail is confidential. The contents may not be dis= closed or used by anyone other than the addressee. Access to this e-mail by= anyone else is unauthorised. If you are not the intended recipient, please notify Airbus immediately and= delete this e-mail. Airbus cannot accept any responsibility for the accuracy or completeness of= this e-mail as it has been sent over public networks. If you have any conc= erns over the content of this message or its Accuracy or Integrity, please = contact Airbus immediately. All outgoing e-mails from Airbus are checked using regularly updated virus = scanning software but you should take whatever measures you deem to be appr= opriate to ensure that this message and any attachments are virus free.