activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jignesh ShaH" <jignesh_s...@persistent.co.in>
Subject broker on the same machine with the producer and consumer on different machine ---- need help Urgent
Date Fri, 04 May 2007 03:57:12 GMT


This is the code of the producer with the explicit Broker running as service
on the same machine as the producer :
I understand that as there are 2 different conectionfactories as the
consumer and the producer are on different machine i.e on different VMs
altogether 
I want the consumer to connect to the broker on other machine which has
producer too.





		ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616");
		System.out.println(connectionFactory.toString());
		String str = null ;
		SimpleMessageConverter convertor = new
SimpleMessageConverter();
		connectionFactory.setUseAsyncSend(true);
		connectionFactory.setDispatchAsync(true);
		connectionFactory.setOptimizeAcknowledge(true);
		connectionFactory.setOptimizedMessageDispatch(true);
		ActiveMQPrefetchPolicy prefetchpolicy = new
ActiveMQPrefetchPolicy();
		prefetchpolicy.setQueuePrefetch(32766);
		connectionFactory.setPrefetchPolicy(prefetchpolicy);
		try 
		{
			QueueConnection connection =
connectionFactory.createQueueConnection();
			Session session =
connection.createQueueSession(false,Session.DUPS_OK_ACKNOWLEDGE);
			Destination destination =
session.createQueue("Xdrqueue");
			MessageProducer producer =
session.createProducer(destination);
			BufferedReader reader = new BufferedReader(new
FileReader(new File("C://Documents and
Settings//jignesh_shah//Desktop//XDR.xml")));
			str =  reader.readLine();
			while(true){
				if(reader.readLine()==null)
					break;
				else
					str +=  reader.readLine();
			}
			System.out.println("First Message sent at : -" +
System.currentTimeMillis());
			for (int i = 0; i < 10000; i++) {
				try {
	
producer.send(convertor.toMessage(str+"\n", session));
				} catch (MessageConversionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JMSException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}	
		  catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (JMSException e) {
			e.printStackTrace();
		}




This is the code for consumer on different machine :

package mqclient;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.QueueConnection;
import javax.jms.Session;


import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ActiveMQPrefetchPolicy;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.SimpleMessageConverter;


public class Client {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			int cnt =0;
			ActiveMQConnectionFactory connectionfactory = new
ActiveMQConnectionFactory("tcp://ps2237:61616");
			System.out.println(connectionfactory);
			connectionfactory.setUseAsyncSend(true);
			connectionfactory.setDispatchAsync(true);
			connectionfactory.setOptimizeAcknowledge(true);
			connectionfactory.setOptimizedMessageDispatch(true);
			ActiveMQPrefetchPolicy prefetchpolicy = new
ActiveMQPrefetchPolicy();
			prefetchpolicy.setQueuePrefetch(32766);
			connectionfactory.setPrefetchPolicy(prefetchpolicy);

			try {
				System.out.println("try enetered");
				QueueConnection connection =
connectionfactory.createQueueConnection();
				Session session =
connection.createQueueSession(false,Session.DUPS_OK_ACKNOWLEDGE);
				Destination destination =
session.createQueue("Xdrqueue");
				MessageConsumer consumer =
session.createConsumer(destination);
				SimpleMessageConverter convertor = new
SimpleMessageConverter();
				while(true)
				{	
					System.out.println("loop enetered");
					Message message =
consumer.receive();
					if(message.equals(null))
					System.out.println("null message") ;
					try {
						
						String str =
(String)convertor.fromMessage(message);
							
						} catch
(MessageConversionException e) {

							e.printStackTrace();
						} catch (JMSException e) {
							e.printStackTrace();
						}
						if (cnt >=10000)
							{
	
System.out.print("Last message received at :- "+
System.currentTimeMillis());
							break;
							}
						++cnt;
				}
			}	catch (JMSException e) {
				e.printStackTrace();
			}
	}
	

}

-----Original Message-----
From: James Strachan [mailto:james.strachan@gmail.com] 
Sent: Thursday, May 03, 2007 7:44 PM
To: users@activemq.apache.org
Subject: Re: facing problems with explicitas well as embedded broker on the
same machine with the producer and consumer on different machine ---- need
help Urgent

What problems are you seeing? (You're not giving us much to go on)...

http://activemq.apache.org/support.html


On 5/3/07, Jignesh ShaH <jignesh_shah@persistent.co.in> wrote:
> facing problems with explicit as well as embedded broker on the same
machine
> with the producer and consumer on different machine ---- need help Urgent
>
>
>
>
>
> What I am doing is running the explicit broker and the producer on the
same
> machine
>
> And the consumer on other machine
>
>
>
> The connectionfactory references generated are different  that's the only
> thing I could find out
>
>
>
>
>
> Regards
>
> Jignesh shah
>
>
> DISCLAIMER
> ==========
> This e-mail may contain privileged and confidential information which is
the property of Persistent Systems Pvt. Ltd. It is intended only for the use
of the individual or entity to which it is addressed. If you are not the
intended recipient, you are not authorized to read, retain, copy, print,
distribute or use this message. If you have received this communication in
error, please notify the sender and delete all copies of this message.
Persistent Systems Pvt. Ltd. does not accept any liability for virus
infected mails.
>


-- 
James
-------
http://macstrac.blogspot.com/


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent
Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it
is addressed. If you are not the intended recipient, you are not authorized to read, retain,
copy, print, distribute or use this message. If you have received this communication in error,
please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd.
does not accept any liability for virus infected mails.

Mime
View raw message