Conntecting to a remote broker.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Conntecting to a remote broker.

iluv2salsa
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.
 
Reply | Threaded
Open this post in threaded view
|

Re: Conntecting to a remote broker.

Andreas Calvo-2
Use the tools provided in the binary distribution.
Look in the example folder (you only need ant installed).
------Mensaje original------
De: iluv2salsa
Para: [hidden email]
Responder a: [hidden email]
Asunto: Conntecting to a remote broker.
Enviado: 25 de feb de 2013 21:24

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-tp4664053.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


--
Andreas Calvo Gómez
Systems Engineer
Scytl Secure Electronic Voting
Plaça Gal·la Placidia, 1-3, 1st floor · 08006 Barcelona
Phone: + 34 934 230 324
Fax:   + 34 933 251 028
http://www.scytl.com

NOTICE: The information in this e-mail and in any of its attachments is
confidential and intended solely for the attention and use of the named
addressee(s). If you are not the intended recipient, any disclosure,
copying,
distribution or retaining of this message or any part of it, without the
prior
written consent of Scytl Secure Electronic Voting, SA is prohibited and
may be
unlawful. If you have received this in error, please contact the sender
and
delete the material from any computer.
Reply | Threaded
Open this post in threaded view
|

Re: Conntecting to a remote broker.

ceposta
In reply to this post by iluv2salsa
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 <[hidden email]> 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-tp4664053.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta
Reply | Threaded
Open this post in threaded view
|

RE: Conntecting to a remote broker.

AMARNATH, Balachandar
In reply to this post by iluv2salsa
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 {
       
        //public void run() {
             public static void main(String[] args ){
            try {

            String url = ActiveMQConnection.DEFAULT_BROKER_URL;
 
                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
               
                // Create a Connection
                Connection connection = connectionFactory.createConnection();
                connection.start();


                // Create a Session
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                // Create the destination (Topic or Queue)
                Destination destination = session.createQueue("TEST.FOO");

                // Create a MessageConsumer from the Session to the Topic or Queue
                MessageConsumer consumer = session.createConsumer(destination);
                // Wait for a message
               
                ArrayList<String> contents = new ArrayList<String>();
                boolean flag = true;
               
                while (flag){
                Message message = consumer.receive(1000);
               
               
               
                if (message instanceof TextMessage) {
                    TextMessage textMessage = (TextMessage) message;
                    String text = textMessage.getText();
                   
                    System.out.println("Received : " + text + " and processing");
                    //Thread.sleep(1500);                    
                   
                    if (text.equalsIgnoreCase("END")){
                    System.out.println("The recvd text is "+text);                    
                    flag = false;
                    }
                    contents.add(text);
                } else {                
                System.out.println("Received : "+message);                
                }  
               
                }  
                System.out.println("Exiting..");
                System.out.println("The contents collected in consumer.java is "+contents.size());
                connection.close();
               
            } catch (Exception e) {
                System.out.println("Caught: " + e);
                e.printStackTrace();
            }
        }
}

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 {
       
        public static void main(String[] args) throws Exception {
               
                  String url = ActiveMQConnection.DEFAULT_BROKER_URL;
     
                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
               
                // Create a Connection
                Connection connection = connectionFactory.createConnection();
                connection.start();
               

                // Create a Session
                Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
               
                // Create the destination (Topic or Queue)
                Destination destination = session.createQueue("TEST.FOO");
               

                // Create a MessageProducer from the Session to the Topic or Queue
                MessageProducer producer = session.createProducer(destination);
                producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
               
                int counter = 0;
                boolean flag = true;
               
                while (counter < 50)
                {
               
                counter++;
                String text = "Message "+counter;// + Thread.currentThread().getName() + " : " + this.hashCode();
                TextMessage message = session.createTextMessage(text);                
                // Tell the producer to send the message
               
                producer.send(message);        
               
                System.out.println("Sent message '" + message.getText() + "'");
                Thread.sleep(1000);
                         
                }
                Thread.sleep(2000);
                producer.send(session.createTextMessage("END"));
               
                Thread.sleep(4000);
                producer.send(session.createTextMessage("END"));
                // Clean up                
                connection.close();
       
        }
    }


Hope this helps :-)


With regards
Bala


-----Original Message-----
From: Christian Posta [mailto:[hidden email]]
Sent: 26 February 2013 05:15
To: [hidden email]
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 <[hidden email]> 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-tp4664053.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



--
*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 disclosed 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 concerns 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 appropriate to ensure that this message and any attachments are virus free.

Reply | Threaded
Open this post in threaded view
|

Re: Conntecting to a remote broker.

iluv2salsa
This post has NOT been accepted by the mailing list yet.
In reply to this post by ceposta
Thank you so much for getting back to me so quickly.  As it turns out, i have been working with this piece of code for a couple of weeks to no avail.  I got it to work when everything runs on the same machine.
Can i run the consumer and the broker on a seperate machine from the producer?
If so, do i need to specify a url when i start activemq?
I am running this code in Virtualbox on a vm Fedora 18 guest, so when i say machine above i mean a vm.

From: ceposta [via ActiveMQ] <[hidden email]>
To: iluv2salsa <[hidden email]>
Sent: Monday, February 25, 2013 6:46 PM
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 <[hidden email]> 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-tp4664053.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>


--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta


If you reply to this email, your message will be added to the discussion below:
http://activemq.2283324.n4.nabble.com/Conntecting-to-a-remote-broker-tp4664053p4664084.html
To unsubscribe from Conntecting to a remote broker., click here.
NAML


Reply | Threaded
Open this post in threaded view
|

Re: Conntecting to a remote broker.

iluv2salsa
This post has NOT been accepted by the mailing list yet.
In reply to this post by ceposta
Thanks, I got it working :)
I am using Virtualbox so...
I put the producer in one fedora 18 vm and the consumer into another fedora 18 vm.
I did not start activemq from the command line to start the broker, but instead i inserted the following code before i started the consumer:
 
BrokerService broker = new BrokerService();
broker.setUseJmx(true);
broker.addConnector("tcp://0.0.0.0:61616");
broker.start();
 
The ip address that i use for the producer is the ip of the machine that activemq and the consumer are running in.
 
But, when i write:  broker.addConnector("tcp://1.2.3.4:61616"), where 1.2.3.4 is the address of the vm that i am running the consumer and broker, it does not work.
Do you know why?
 

From: ceposta [via ActiveMQ] <[hidden email]>
To: iluv2salsa <[hidden email]>
Sent: Monday, February 25, 2013 6:46 PM
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 <[hidden email]> 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-tp4664053.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>


--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta


If you reply to this email, your message will be added to the discussion below:
http://activemq.2283324.n4.nabble.com/Conntecting-to-a-remote-broker-tp4664053p4664084.html
To unsubscribe from Conntecting to a remote broker., click here.
NAML


Reply | Threaded
Open this post in threaded view
|

Re: Conntecting to a remote broker.

iluv2salsa
This post has NOT been accepted by the mailing list yet.
In reply to this post by AMARNATH, Balachandar
Thank you very much for your quick response. I really appreciate it :)

From: "AMARNATH, Balachandar [via ActiveMQ]" <[hidden email]>
To: iluv2salsa <[hidden email]>
Sent: Tuesday, February 26, 2013 12:38 AM
Subject: RE: Conntecting to a remote broker.

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 {
       
        //public void run() {
             public static void main(String[] args ){
            try {

            String url = ActiveMQConnection.DEFAULT_BROKER_URL;
 
                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
               
                // Create a Connection
                Connection connection = connectionFactory.createConnection();
                connection.start();


                // Create a Session
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                // Create the destination (Topic or Queue)
                Destination destination = session.createQueue("TEST.FOO");

                // Create a MessageConsumer from the Session to the Topic or Queue
                MessageConsumer consumer = session.createConsumer(destination);
                // Wait for a message
               
                ArrayList<String> contents = new ArrayList<String>();
                boolean flag = true;
               
                while (flag){
                Message message = consumer.receive(1000);
               
               
               
                if (message instanceof TextMessage) {
                    TextMessage textMessage = (TextMessage) message;
                    String text = textMessage.getText();
                   
                    System.out.println("Received : " + text + " and processing");
                    //Thread.sleep(1500);                    
                   
                    if (text.equalsIgnoreCase("END")){
                    System.out.println("The recvd text is "+text);                    
                    flag = false;
                    }
                    contents.add(text);
                } else {                
                System.out.println("Received : "+message);                
                }  
               
                }  
                System.out.println("Exiting..");
                System.out.println("The contents collected in consumer.java is "+contents.size());
                connection.close();
               
            } catch (Exception e) {
                System.out.println("Caught: " + e);
                e.printStackTrace();
            }
        }
}

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 {
       
        public static void main(String[] args) throws Exception {
               
                  String url = ActiveMQConnection.DEFAULT_BROKER_URL;
     
                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
               
                // Create a Connection
                Connection connection = connectionFactory.createConnection();
                connection.start();
               

                // Create a Session
                Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
               
                // Create the destination (Topic or Queue)
                Destination destination = session.createQueue("TEST.FOO");
               

                // Create a MessageProducer from the Session to the Topic or Queue
                MessageProducer producer = session.createProducer(destination);
                producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
               
                int counter = 0;
                boolean flag = true;
               
                while (counter < 50)
                {
               
                counter++;
                String text = "Message "+counter;// + Thread.currentThread().getName() + " : " + this.hashCode();
                TextMessage message = session.createTextMessage(text);                
                // Tell the producer to send the message
               
                producer.send(message);        
               
                System.out.println("Sent message '" + message.getText() + "'");
                Thread.sleep(1000);
                         
                }
                Thread.sleep(2000);
                producer.send(session.createTextMessage("END"));
               
                Thread.sleep(4000);
                producer.send(session.createTextMessage("END"));
                // Clean up                
                connection.close();
       
        }
    }


Hope this helps :-)


With regards
Bala


-----Original Message-----
From: Christian Posta [mailto:[hidden email]]
Sent: 26 February 2013 05:15
To: [hidden email]
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 <[hidden email]> 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-tp4664053.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>


--
*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 disclosed 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 concerns 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 appropriate to ensure that this message and any attachments are virus free.



If you reply to this email, your message will be added to the discussion below:
http://activemq.2283324.n4.nabble.com/Conntecting-to-a-remote-broker-tp4664053p4664090.html
To unsubscribe from Conntecting to a remote broker., click here.
NAML