[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 741
  • Last Modified:

jms example issue

Hi,

I am trying below jms example.

package jms;

import java.util.Properties;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Producer {
	public Producer() {
		try {
			Properties props = new Properties();
			props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
					"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
			props.setProperty(Context.PROVIDER_URL, "tcp://localhost:91919");
			Context context = new InitialContext(props);
			QueueConnectionFactory tcf = (QueueConnectionFactory) context
					.lookup("ConnectionFactory");
			QueueConnection conn = tcf.createQueueConnection();
			conn.start();
			QueueSession session = conn.createQueueSession(false,
					Session.CLIENT_ACKNOWLEDGE);
			Queue queue = (Queue) context.lookup("movingQueues/Audios");
			QueueSender sender = session.createSender(queue);
			/*Send messages all users say like three*/
			TextMessage msg1 = session.createTextMessage();
			msg1.setText("howdy");
			sender.send(msg1);
			System.out.println("sent the important message");
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new Producer();
	}
}








package jms;

import java.util.Properties;

import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Consumer {
	public Consumer() {
		try {
			Properties props = new Properties();
			props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
					"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
			props.setProperty(Context.PROVIDER_URL, "tcp://localhost:91919");
			Context context = new InitialContext(props);
			QueueConnectionFactory tcf = (QueueConnectionFactory) context
					.lookup("ConnectionFactory");
			QueueConnection conn = tcf.createQueueConnection();
			conn.start();
			QueueSession session = conn.createQueueSession(false,
					Session.CLIENT_ACKNOWLEDGE);
			Queue queue = (Queue) context.lookup("movingQueues/Audios");
			QueueReceiver reciever = session.createReceiver(queue);
			reciever.setMessageListener(new MyListener());
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new Consumer();
	}
}













package jms;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

class MyListener implements MessageListener {
	public void onMessage(Message message) {
		TextMessage msg = null;
		try {
			if (message instanceof TextMessage) {
				msg = (TextMessage) message;
				System.out.println("Deciphering message: " + msg.getText());
			} else {
				System.out.println("Check if wrong kind of message: "
						+ message.getClass().getName());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

Open in new window

I am getting issues when i right click on Consumer and Run as Java application


log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:91919. Reason: java.net.ConnectException:


I have not understood the flow of the example. What is exactly happening in above 3 classes. please advise.

I am using eclipse and installed active mq 5 as well.
0
gudii9
Asked:
gudii9
  • 18
  • 7
2 Solutions
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I am getting issues when i right click on Consumer and Run as Java application

The first too lines are just warning about log4j, you can follow the link to read about needing to configure log4j properly, but those are just warnings and so can be ignored for the moment.

The real problem is the third line...
javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:91919. Reason: java.net.ConnectException:
Which is basically just saying that the consumer couldn't connect to the ActiveMQ server. Do you have ActiveMQ running on the same machine? Also, ActiveMQ's default port to listen on is 61616 (not 91919) so unless you have specifically changed the ActiveMQ configuration yourself, try changing the code to connect to port 61616 and see if that helps.
0
 
gudii9Author Commented:
>>ActiveMQ running on the same machine?

correct. it is running on my windows vista laptop. How to open active mq admin console or UI to see and configure queues, topics etc visually.(does this show on jboss admin console , i have jboss 7 running).
I am bit confused between jboss app server and activemq roles what does what and how to configure each to run the jms examples?


 As of now i am CDing to bin directory from command prompt
C:/Software/activeMq/bin>activemq
which is starting the activemq

>>ActiveMQ's default port to listen on is 61616 (not 91919)

I will try and let you know soon
0
 
gudii9Author Commented:
So all i need to do is

1. start and run activeMQ server after CDing to bin directory from command prompt
C:/Software/activeMq/bin>activemq
2. Fix the port number in Consumer.java
3. Right click on Consumer.java and run as java application

Then what is the output i supposed to see and where i will see it. Is this example working for you?
please advise
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
gudii9Author Commented:
i started qctivemq server as below

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\ganesha>cd C:\software\apache-activemq-5.9.1\bin

C:\software\apache-activemq-5.9.1\bin>activemq
Java Runtime: Oracle Corporation 1.7.0_51 C:\Program Files\Java\jdk1.7.0_51\jre
  Heap sizes: current=1013632k  free=996854k  max=1013632k
    JVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.c
onfig.file=logging.properties -Djava.security.auth.login.config=C:\software\apac
he-activemq-5.9.1\bin\..\conf\login.config -Dactivemq.classpath=C:\software\apac
he-activemq-5.9.1\bin\..\conf;C:\software\apache-activemq-5.9.1\bin\../conf;C:\s
oftware\apache-activemq-5.9.1\bin\../conf; -Dactivemq.home=C:\software\apache-ac
tivemq-5.9.1\bin\.. -Dactivemq.base=C:\software\apache-activemq-5.9.1\bin\.. -Da
ctivemq.conf=C:\software\apache-activemq-5.9.1\bin\..\conf -Dactivemq.data=C:\so
ftware\apache-activemq-5.9.1\bin\..\data -Djava.io.tmpdir=C:\software\apache-act
ivemq-5.9.1\bin\..\data\tmp
Extensions classpath:
  [C:\software\apache-activemq-5.9.1\bin\..\lib,C:\software\apache-activemq-5.9.
1\bin\..\lib\camel,C:\software\apache-activemq-5.9.1\bin\..\lib\optional,C:\soft
ware\apache-activemq-5.9.1\bin\..\lib\web,C:\software\apache-activemq-5.9.1\bin\
..\lib\extra]
ACTIVEMQ_HOME: C:\software\apache-activemq-5.9.1\bin\..
ACTIVEMQ_BASE: C:\software\apache-activemq-5.9.1\bin\..
ACTIVEMQ_CONF: C:\software\apache-activemq-5.9.1\bin\..\conf
ACTIVEMQ_DATA: C:\software\apache-activemq-5.9.1\bin\..\data
Loading message broker from: xbean:activemq.xml
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@a7ef62: startu
p date [Tue Aug 05 23:16:54 EDT 2014]; root of context hierarchy
 INFO | PListStore:[C:\software\apache-activemq-5.9.1\bin\..\data\localhost\tmp_
storage] started
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\software\apache-a
ctivemq-5.9.1\bin\..\data\kahadb]
 INFO | KahaDB is version 5
 INFO | Recovering from the journal ...
 INFO | Recovery replayed 4828 operations from the journal in 0.789 seconds.
 INFO | Apache ActiveMQ 5.9.1 (localhost, ID:ganesha-PC-57259-1407295020848-0:1)
 is starting
 INFO | Listening for connections at: tcp://ganesha-PC:61616?maximumConnections=
1000&wireFormat.maxFrameSize=104857600
 INFO | Connector openwire started
 INFO | Listening for connections at: amqp://ganesha-PC:5672?maximumConnections=
1000&wireFormat.maxFrameSize=104857600
 INFO | Connector amqp started
 INFO | Listening for connections at: stomp://ganesha-PC:61613?maximumConnection
s=1000&wireFormat.maxFrameSize=104857600
 INFO | Connector stomp started
 INFO | Listening for connections at: mqtt://ganesha-PC:1883?maximumConnections=
1000&wireFormat.maxFrameSize=104857600
 INFO | Connector mqtt started
 INFO | Listening for connections at ws://ganesha-PC:61614?maximumConnections=10
00&wireFormat.maxFrameSize=104857600
 INFO | Connector ws started
 INFO | Apache ActiveMQ 5.9.1 (localhost, ID:ganesha-PC-57259-1407295020848-0:1)
 started
 INFO | For help or more information please see: http://activemq.apache.org
 WARN | Store limit is 102400 mb (current store usage is 1 mb). The data directo
ry: C:\software\apache-activemq-5.9.1\bin\..\data\kahadb only has 90433 mb of us
able space - resetting to maximum available disk space: 90435 mb
 INFO | ActiveMQ WebConsole available at http://localhost:8161/
 INFO | Initializing Spring FrameworkServlet 'dispatcher'
 INFO | jolokia-agent: No access restrictor found at classpath:/jolokia-access.x
ml, access to all MBeans is allowed


And ran consumer.java 'run as java application'

I see console as below

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/apache/activemq/activemq-all/5.8.0/activemq-all-5.8.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/slf4j/slf4j-nop/1.6.4/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.



I do not see anything meaningful. please advise on how to run this.
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
So the lack of error messages is a good sign. The fact that you aren't getting anything useful though is probably just because there is no messages on the queue, for your consumer to consume.

So start your ActiveMQ server (like you are already doing) and then run the Producer code so that a message is put on to the queue. And then run your Consumer and it should receive the message that the Producer sent to the queue.
0
 
gudii9Author Commented:
oh. I will try that and let you know.

Do i need to do any steps to create queue. I have not remember doing anything to create queue. How , where do i create it. What name i supposed to give to the queue. Do i need jboss server also to run this example. I just created simple java project. I do not need to create EJB, EAR, WAR etc project similar to EJB application right?

I do not neeed to run on server also right?
just run as java application should be good enough right.

Please advise
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Do i need to do any steps to create queue
As long as ActiveMQ has the default configuration, it should automatically create the queue the first time that it is posted to or consumed from. So I would say "no" you shouldn't have to create it manually.

Do i need jboss server also to run this example?
I just created simple java project. I do not need to create EJB, EAR, WAR etc project similar to EJB application right?
I do not neeed to run on server also right?
Just run as java application should be good enough right?

No, you don't need JBoss or any other "server" to run this. Yes, you can just create a simple "Java Project" for your Producer and Consumer code. And as you have mentioned, yes, just "Run As..." a "Java Application".
0
 
gudii9Author Commented:
when i ran Producer o got below console message saying message sent

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/apache/activemq/activemq-all/5.8.0/activemq-all-5.8.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/slf4j/slf4j-nop/1.6.4/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Message Sent



when i ran consumer.java i got below message saying message read

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/apache/activemq/activemq-all/5.8.0/activemq-all-5.8.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/slf4j/slf4j-nop/1.6.4/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Reading message: Hi John, How are you doing


How do i see the generated queue on the activemq server. Where i have to go to see the queue. which location i have to go to see it
My activemq server is at
C:\software\apache-activemq-5.9.1\bin

Please advise
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
If you look back through the logs that you have posted, regarding the startup of ActiveMQ, you will see this line...
INFO | ActiveMQ WebConsole available at http://localhost:8161/
So you should be able to navigate to that link to see the ActiveMQ admin console web page, and from there you can click on "Manage ActiveMQ broker" and then select "Queues" from the link on the pages menu bar near the top (just under the big ActiveMQ text)

You will see the queues that have been created, one of them should be the queue name mentioned in the code for both Producer and Consumer. Also, if you refresh that page AFTER running the Producer code but BEFORE running the Consumer code, you should see the "Number Of Pending Messages" column have a value of "1" and you can click on the link that is the queue's name and it will list the messages that are currently pending on the queue. You can then also click on individual messages to see some details about them.
0
 
gudii9Author Commented:
when i went to

http://localhost:8161/

clicked 'mamnmage activemq broker' link it is asking for username and password. I do not remember giving anything like that.
I tried username as adming and passwordfa also as admin which did not work.

Is there is any default username and password i should enter. please advise
0
 
gudii9Author Commented:
i tried guest/password combination that also did not work.
http://activemq.apache.org/security.html
 please advise
Queue.jpg
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I am pretty sure that all installations of ActiveMQ that I have done come with no security setup as default, although I have only used versions up to and including 5.8 so this may have changed with version 5.9

But have a look at the files in "C:\software\apache-activemq-5.9.1\conf" particularly "jetty.xml" and/or "jetty-realm.properties" to find out how the web console security is setup.
0
 
gudii9Author Commented:
jetty xml looks like

  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="securityLoginService" class="org.eclipse.jetty.security.HashLoginService">
        <property name="name" value="ActiveMQRealm" />
        <property name="config" value="${activemq.conf}/jetty-realm.properties" />
    </bean>

    <bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint">
        <property name="name" value="BASIC" />
        <property name="roles" value="user,admin" />
        <!-- set authenticate=false to disable login -->
        <property name="authenticate" value="true" />
    </bean>
    <bean id="adminSecurityConstraint" class="org.eclipse.jetty.util.security.Constraint">
        <property name="name" value="BASIC" />
        <property name="roles" value="admin" />
         <!-- set authenticate=false to disable login -->
        <property name="authenticate" value="true" />
    </bean>
    <bean id="securityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
        <property name="constraint" ref="securityConstraint" />
        <property name="pathSpec" value="/api/*,/admin/*,*.jsp" />

Open in new window




Not sure what is username and passsword
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
But have a look at the files in "C:\software\apache-activemq-5.9.1\conf" particularly "jetty.xml" and/or "jetty-realm.properties" to find out how the web console security is setup
0
 
gudii9Author Commented:
"jetty-realm.properties"  says as

# Defines users that can access the web (console, demo, etc.)
# username: password [,rolename ...]
admin: admin, admin
user: user, user

not sure what it means by username password(it sound like both admin, admin?? but which did not work to me earlier?? please advise)
0
 
gudii9Author Commented:
actually it worked fine now with admin, admin as attached. wheni ran Producer java number of messages getting increased one by one(now it shows 3).

When i run Consumer.java the number is not reducing one by one.

I thought it becomes 3-->2-->1-->0
But that 3 remains same even after running Consumer.java 2 times. Please advise how to fix this issue
queueAdmin1.jpg
0
 
gudii9Author Commented:
other attachment
queueAdmin2.jpg
0
 
gudii9Author Commented:
how the EJB MDB queue and the JMS ACTIVE MQ queue are different. How the jms with or without spring are differert?please advise
0
 
gudii9Author Commented:
when i run consumer i just see message like

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/apache/activemq/activemq-all/5.8.0/activemq-all-5.8.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/slf4j/slf4j-nop/1.6.4/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


Only randomly it prints message like
Hi John, How are you doing.
You received message like that
I wonder what special cases it reads and prints the above message and where from it is prinitng it. please advise
0
 
gudii9Author Commented:
when i ran consumer.java i got below message saying Reading message: Hi John, How are you doing as below only once.


SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/apache/activemq/activemq-all/5.8.0/activemq-all-5.8.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/ganesha/.m2/repository/org/slf4j/slf4j-nop/1.6.4/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Reading message: Hi John, How are you doing

When i run my Consumer.java i am not getting that message anymore. Message is not being read any more from queue anymore. I wonder why the Consumer is not working any more. Please advise
0
 
gudii9Author Commented:
when i ran in debug mode after line 25 when entered line 26 i see the console message like' Reading messagee: Hi John, How are you doing"

When i run as regular mode(not debug mode) i am not getting message like' Reading messagee: Hi John, How are you doing"
Please advise
QueueConsumer.jpg
0
 
gudii9Author Commented:
how to know if this point to point or pub-sub messaging model? Isa it is durablesubcribing model? How have multiple conumers reading the messages
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
It is a bit hard to debug what your problem is from here. All I can say, is to make sure that you only ever have the one Consumer program running at one time, ie. the Consumer will continue running after displaying the message received, so make sure you explicitly kill it before starting up another consumer. You can check how many consumers are connected to a queue in the admin web page for ActiveMQ. The number should be 0 when no consumer is running and 1 when you start the consumer, if it is more that 1 then the messages may be getting consumed by a consumer that you didn't realise is running.

how to know if this point to point or pub-sub messaging model?
Point-to-point is probably not the best way to describe it, but yes this is what you are using because if you look at your Consumer/Producer code, you can see that it is dealing with "Queue". For Publish/Subscribe model, the code would be using "Topic" instead.

Isa it is durablesubcribing model?
Durable subscriptions are only applicable to Topics, so no they don't have anything to do with your current code.

How have multiple conumers reading the messages
It's not 100% clear what you are asking here. Did you mean... "How do you setup multiple consumers reading messages?"  If so, then there is nothing really special to set this up. You can just start up multiple consumers and the broker (ActiveMQ) will do the job of sending each message to one of the consumers. Exactly which one it goes to is hard to define, it won't also be a perfect "round-robin" type of setup but what you can be sure of, is if you had a large number of pending messages then the broker will make sure that the load is fairly evenly spread between the consumers.

If however, by the above question, you actually wanted each message to go to all consumers, then this is what is meant by publish/subscribe and you would have to change the Consumer and Producer code to use a "Topic" rather than a "Queue"
0
 
gudii9Author Commented:
My example running fine from eclipse but when i run Producer.java from command prompt getting below errors.

C:\Users\ganesha\kepler_workspace\05122014_JMS\SpringJMSDemo\src\main\java\jms>
avac producer.java
producer.java:4: error: package javax.jms does not exist
import javax.jms.*;
^
producer.java:16: error: cannot find symbol
                        QueueConnectionFactory tcf = (QueueConnectionFactory) c
ntext
                        ^
  symbol:   class QueueConnectionFactory
  location: class Producer
producer.java:16: error: cannot find symbol
                        QueueConnectionFactory tcf = (QueueConnectionFactory) c
ntext
                                                      ^
  symbol:   class QueueConnectionFactory
  location: class Producer
producer.java:18: error: cannot find symbol
                        QueueConnection conn = tcf.createQueueConnection();
                        ^
  symbol:   class QueueConnection
  location: class Producer
producer.java:20: error: cannot find symbol
                        QueueSession session = conn.createQueueSession(false,
                        ^
  symbol:   class QueueSession
  location: class Producer
producer.java:21: error: cannot find symbol
                                        Session.CLIENT_ACKNOWLEDGE);
                                        ^
  symbol:   variable Session
  location: class Producer
producer.java:22: error: cannot find symbol
                        Queue queue = (Queue) context.lookup("dynamicQueues/Mov
es");
                        ^
  symbol:   class Queue
  location: class Producer
producer.java:22: error: cannot find symbol
                        Queue queue = (Queue) context.lookup("dynamicQueues/Mov
es");
                                       ^
  symbol:   class Queue
  location: class Producer
producer.java:23: error: cannot find symbol
                        QueueSender sender = session.createSender(queue);
                        ^
  symbol:   class QueueSender
  location: class Producer
producer.java:25: error: cannot find symbol
                        TextMessage msg1 = session.createTextMessage();
                        ^
  symbol:   class TextMessage
  location: class Producer
10 errors

C:\Users\ganesha\kepler_workspace\05122014_JMS\SpringJMSDemo\src\main\java\jms>


How to resolve them. Please advise
0
 
gudii9Author Commented:
package jms;

import java.util.Properties;

import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;

public class ConsumerTwo {
	public ConsumerTwo() {
		try {
			Properties props = new Properties();
			props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
					"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
			props.setProperty(Context.PROVIDER_URL, "tcp://localhost:61616");
			Context context = new InitialContext(props);
			QueueConnectionFactory tcf = (QueueConnectionFactory) context
					.lookup("ConnectionFactory");
			QueueConnection conn = tcf.createQueueConnection();
			conn.start();
			QueueSession session = conn.createQueueSession(false,
					Session.CLIENT_ACKNOWLEDGE);
			Queue queue = (Queue) context.lookup("dynamicQueues/Movies");
			QueueReceiver reciever = session.createReceiver(queue);
			reciever.setMessageListener(new MyListener());
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new ConsumerTwo();
	}
}

Open in new window



I wrote one other consumer (ConsumerTwo) and ran in debug mode by putting breakpoint that is also reading on the same queue same old messages(after line 25 at line 26) as they were not deleted by old Consumer.java when i ran as java application, Please advise


i am trying topic example by creating publisher in one instance of eclipse in workspace called XYZ
and subscriber on other isntance of eclipse in workapce called abc

so that when i publish some messages i want my subscrier automatically notified and get those messages.

workspace abc is not able to understand imports like
import javax.jms.* etc

I looked below url to get the jars
http://www.fluffycat.com/Java/JMS-With-A-Queue/

there are no jars. Any simple complete example on this with all needed jars on both queue, topic, point to point, pub-sub, durable-non durable topics using eclispe and apache mq. please advise


when i run topic subscriver from flugycat link getting below error
http://www.fluffycat.com/Java/JMS-With-A-Topic/

Naming Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
Exception in thread "main" java.lang.NullPointerException
      at jmsTopic.WeasleyQuidditchTopicSubscriber.<init>(WeasleyQuidditchTopicSubscriber.java:53)
      at jmsTopic.WeasleyQuidditchTopicSubscriber.main(WeasleyQuidditchTopicSubscriber.java:17)



Please advise
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 18
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now