i want to create a very simple JMS standalone client to a JMS Topic hosted on my Glassfish server.
My project is built using maven.
I know there seems to be some kind of mess concerning JMS dependencies to use, so, which dependencies shouls I use in my pom to
- Connect to my JNDI context
- Be able to read my JMS topic ?
My Java test method is
/** Thanks to WELD CDI, this method is not static */
public void main(@Observes ContainerInitialized event) throws Throwable {
Context context = new InitialContext();
ConnectionFactory factory = (ConnectionFactory) context.lookup(JMSNotifierConstants.CONNECTION_FACTORY_NAME);
Connection connection = factory.createConnection();
Topic topic = (Topic) context.lookup(JMSNotifierConstants.NOTIFICATION_TOPIC);
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(topic);
connection.start();
while (true) {
Message received = consumer.receive();
System.out.println(received);
}
}
And my pom contains, for now, the following dependencies
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-se</artifactId>
<version>1.0.1-Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-logger</artifactId>
<version>1.0.0-CR2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.jms</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>appserv-rt</artifactId>
<version>3.1</version>
</dependency>