tags:

views:

150

answers:

1

Hi guys,

Every example I've seen on the web, e.g. http://www.codeproject.com/KB/docview/jms_to_jms_bridge_activem.aspx, creates a publisher and subscriber with a public static void main method. I don't think that'll work for my web application.

I'm learning JMS and I've setup Apache ActiveMQ to run on JBoss 5 and Tomcat 6 (with no glitches).

I'm writing a messaging JMS service that needs to send email asynchronously.

I've already written a JMS subscriber that receives the message (the class inherits MessageListener).

My question is simple:

  • How do I write a publisher that will so that my web applications can call it? Does it have to be published somewhere? My thought is to create a publisher with a no-attribute constructor (in there) and get the MessageQueue Factory, etc. from the JNDI pool (in the constructor). Is my idea correct?
  • How do I subscribe my subscriber to the Queue Receiver? (So far, the subscriber has no constructor, and if I write a constructor, do I always subscribe myself to the Queue receiver?)

Thanks for your help, sorry if my terminology is not up to scratch, there are too many java terminologies that I get lost sometimes (maybe a java GPS will do! :-) )

PS Is there a tutorial out there that explains how to write a "better" (better can mean anything, but in my case it's all about performance in high demand requests) JMS Publisher and Subscriber that I can run on Application Server such as JBoss or Glassfish? Don't forget that the JMS application will needs a "guarantee" uptime as many applications will use this.

A: 

If you are using Spring try JmsTemplate else just open up the source code and read through it ;)

http://www.java.happycodings.com/Other/code53.html

http://www.agitar.com/openquality/spring/org/springframework/jms/core/JmsTemplate.java.html

Calm Storm
Sorry, I'm not using Spring for this project.
The Elite Gentleman
Can you check the link "http://www.java.happycodings.com/Other/code53.html" that has a simple link of how to do it :)
Calm Storm
Thanks, but doesn't really help in my case.
The Elite Gentleman
You actually helped by showing the JmsTemplate.java code. However, I refined it better because it certain "practices" I didn't really like.
The Elite Gentleman