If your topic consumer subscribes to the topic after the messages have been published, then it will not receive those messages. It will only receive messages that are published while it has an active subscription.
If you want your topic consumer to receive messages that are published while it did not have an active subscription, then check out durable topic subscriptions. But even with durable subscriptions, your consumer will not receive messages that were published prior to it first establishing its durable subscription. However, check out an AMQ-specific feature called 'retroactive consumers'. http://activemq.apache.org/retroactive-consumer.html Joe http://www.ttmsolutions.com dj_jay_smith wrote: > > Hi All, > > > I am starting to write a simple program to read message from a topic that > I have created and posted message to from anothe program. But for some > reason when I call "consumer.receive(10000)" then I always get null > returned even though there are messages on the Topic ready to be > collected. > > I am sure that it is a simple stupid mistake somewhere, but I can not see > it so help is needed. I am new to JMS so I appreciate any help that can > be offered. > > My code; > > Context jndiContext = new InitialContext(); > TopicConnectionFactory connectionFactory > =TopicConnectionFactory)jndiContext.lookup(this.connFactory); > > Connection connection = connectionFactory.createConnection(); > Session session = connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > Topic dest = (Topic)jndiContext.lookup(this.destination); > > connection.start(); > MessageConsumer consumer = session.createConsumer(dest); > > then later; > > Message mess = consumer.receive(10000); //returns null! > > I can see my consumer connect to the topic (Number Of Consumers in > activemq admin console is incremented), and I have several message waiting > but they are never collected and I don't know why! > > I am running activemq on a remote server, but it can't be a connection > problem as I am able to send messages, access the admin console and I > would expect an exception to be thrown if this was the case. > > Thanks for you help. > > -- View this message in context: http://old.nabble.com/consumer.receive-always-returns-null-tp27340066p27340730.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.
