activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kumar Pawan <pawankrm...@gmail.com>
Subject Sending a message but not able to receieve this mesage.
Date Thu, 17 Jun 2010 16:08:20 GMT

Sending a message but not able to receieve this mesage. when i change message
QueueName then its able receieve for few messsages again i have to change
the queue name to receieve next messages. But i am able to see every message
sent and receive in ActiveMQ admin. please help me why every time i have
change queue name.

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.*;

public class MsgReceiver implements MessageListener {
private static int ackMode;
private static String messageQueueName;
private static String messageBrokerUrl;

private Session session;
private boolean transacted = false;
MessageConsumer consumer = null;
CreateDS createDS = new CreateDS();

static {
messageBrokerUrl = ReadProperty.getValues("messageBrokerUrl");
messageQueueName = "tmsmevent.messages";
ackMode = Session.AUTO_ACKNOWLEDGE;
}

private void setupMessageQueueConsumer() throws Exception {

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
messageBrokerUrl);
Connection connection = null;

try 
{
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(transacted, ackMode);
Destination adminQueue = session.createQueue(messageQueueName);
// Set up a consumer to consume messages off of the admin queue
consumer = session.createConsumer(adminQueue);
MsgReceiver msgReceiver = new MsgReceiver();
consumer.setMessageListener(msgReceiver);
} 
catch (Exception e) 
{
// Handle the exception appropriately
e.printStackTrace();
}
/*
* finally 
* { 
* try 
* { 
* if (consumer != null) 
* { 
* consumer.close(); 
* }
* 
* if (session != null) 
* { 
* session.close(); 
* }
* 
* if (connection != null) 
* { 
* connection.close(); 
* } 
* } 
* catch (Exception e)
* { 
* e.printStackTrace(); 
* } 
* }
*/
}

public void onMessage(Message message) {
try 
{

if (message instanceof TextMessage) 
{

TextMessage txtMsg = (TextMessage) message;
String messageText = txtMsg.getText();

System.out.println("Job Name: " + messageText);
}
} 
catch (Exception e) 
{
// Handle the exception appropriately
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
new MsgReceiver().setupMessageQueueConsumer();
}
} 


-- 
View this message in context: http://old.nabble.com/Sending-a-message-but-not-able-to-receieve-this-mesage.-tp28916420p28916420.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Mime
View raw message