activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yanhongsan <xinchunli1...@163.com>
Subject Problem with Persistence
Date Tue, 06 Jan 2009 01:17:50 GMT

I found a problem.When I send 100 messages to the activemq server the first
time , I can receive the messages well. However I cannot send any message to
the server later. Because the queue is blocked. If the 100 sended messages
just now is not persistent ,I can receive messages and send message. The
sender code and receiver code are to create a connection and close the
connection every time. It follows:
the Sender:
	int messageCount  = 100;
	boolean persistent = true;
	for(int i = 0 ; i < messageCount; i++)
    	{
    		ProducerTool producerTool = new ProducerTool();
        	producerTool.run(i);
    	}
	public void run(int i)
	{
		....
		Connection conn = connectionFactory.createConnection();
            	connection.start();
		// Create the producer.
            	MessageProducer producer = session.createProducer(destination);
            	if (persistent) {
                	producer.setDeliveryMode(DeliveryMode.PERSISTENT);
            	} else {
                	producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            	}
		
		sendMessage();
		...

		//close
		session.close();
                connection.close();	
	}

the Receiver:
	while(true)
	{
		ConsumerTool consumer = new ConsumerTool();
		consumer.consume();
	}

	public void consume()throws JMSException
	{
		String url = "tcp://129.1.5.95:61616";
		String queueName = "0F2";
		ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(url);
		ActiveMQConnection connection =
(ActiveMQConnection)connectionFactory.createConnection();
        	connection.start(); 
        	Session  session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
		Destination destination = session.createQueue(queueName);
        	
		MessageConsumer consumer = (MessageConsumer)
session.createConsumer(destination);
		Message message = consumer.receive(100);
		if(message instanceof TextMessage)
		{
			TextMessage txtmsg = (TextMessage)message;
				
			System.out.println("received: " + txtmsg.getText());
				
		}
		else
		{
			System.out.println("not textmessage");
		}
		
        	session.close();
        	connection.close();
	}

I know the mode of connection that is to create and close every time is not
well. But it is my demand. Can any one help me?
-- 
View this message in context: http://www.nabble.com/Problem-with-Persistence-tp21301566p21301566.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message