Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
983 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.jboss.seam.jms</groupId> | ||
<artifactId>seam-jms-parent</artifactId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>seam-jms-example-statuswatcher</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<name>Seam StatusWatcher Example (JMS)</name> | ||
|
||
<properties> | ||
<jboss.home>${env.JBOSS_HOME}</jboss.home> | ||
<jboss.domain>default</jboss.domain> | ||
<seam.jms.version>3.0.0-SNAPSHOT</seam.jms.version> | ||
<jsf.version>2.0.2-FCS</jsf.version> | ||
<ajax4jsf.version>1.0.5</ajax4jsf.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.jboss.seam.jms</groupId> | ||
<artifactId>seam-jms-api</artifactId> | ||
<version>${seam.jms.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.seam.jms</groupId> | ||
<artifactId>seam-jms-impl</artifactId> | ||
<version>${seam.jms.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>slf4j-api</artifactId> | ||
<groupId>org.slf4j</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.spec.javax.jms</groupId> | ||
<artifactId>jboss-jms-api_1.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.spec.javax.ejb</groupId> | ||
<artifactId>jboss-ejb-api_3.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hibernate.javax.persistence</groupId> | ||
<artifactId>hibernate-jpa-2.0-api</artifactId> | ||
<version>1.0.0.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Common to JEE and Servlet containers --> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.spec.javax.annotation</groupId> | ||
<artifactId>jboss-annotations-api_1.1_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<classifier>jdk15</classifier> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.faces</groupId> | ||
<artifactId>jsf-api</artifactId> | ||
<version>${jsf.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.web</groupId> | ||
<artifactId>el-impl</artifactId> | ||
<scope>runtime</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.el</groupId> | ||
<artifactId>el-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>jms-statuswatcher</finalName> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>distribution</id> | ||
<activation> | ||
<property> | ||
<name>release</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>jbossas</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>jboss-maven-plugin</artifactId> | ||
<version>1.4.1</version> | ||
<configuration> | ||
<jbossHome>${jboss.home}</jbossHome> | ||
<serverName>${jboss.domain}</serverName> | ||
<fileNames> | ||
<param>${basedir}/src/main/resources-jboss6/statuswatcher-hornetq-jms.xml</param> | ||
<param>${project.build.directory}/${project.build.finalName}.${project.packaging}</param> | ||
</fileNames> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Seam JMS StatusWatcher example | ||
============================== | ||
|
||
To run the example on JBossAS 6 you need to do the following: | ||
|
||
* add this line to $JBOSS_HOME/server/*/deploy/hornetq-configuration.xml: | ||
|
||
<security-enabled>false</security-enabled> | ||
|
||
* build and deploy the app: | ||
|
||
mvn clean install jboss:hard-deploy | ||
|
||
This will copy the resulting war along with a hornetq configuration file to a JBossAS | ||
deploy directory. | ||
|
||
The application simulates sending your status messages to a server via JMS Queue, the server | ||
then stores the messages in a database and distributes them to a general JMS Topic where all people | ||
can see statuses of all the other people. | ||
|
||
The webpage where you can find statuses of other people is available at: | ||
|
||
http://localhost:8080/jms-statuswatcher/watchstatus.jsf | ||
|
||
If you tick "Follow all" the page will be periodically refreshed (the interval is 20 seconds) and | ||
status messages will be received. Furthermore, you can receive all messages immediately by clicking | ||
on "Receive". If you are interested in all the messages that came to the server, click "History". | ||
|
||
You can send your status to the server via (opening it in a different browser window): | ||
|
||
http://localhost:8080/jms-statuswatcher/sendstatus.jsf | ||
|
||
Of course, you can open several browser windows, one for each user, and watch incomming statuses. | ||
|
72 changes: 72 additions & 0 deletions
72
.../src/main/java/org/jboss/seam/jms/example/statuswatcher/messagedriven/DistributorMDB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.jboss.seam.jms.example.statuswatcher.messagedriven; | ||
|
||
import javax.inject.Inject; | ||
import javax.jms.Connection; | ||
import javax.jms.ConnectionFactory; | ||
import javax.jms.JMSException; | ||
import javax.jms.Message; | ||
import javax.jms.MessageListener; | ||
import javax.jms.ObjectMessage; | ||
import javax.jms.Session; | ||
import javax.jms.Topic; | ||
import javax.jms.TopicPublisher; | ||
import javax.jms.TopicSession; | ||
import javax.annotation.Resource; | ||
import javax.ejb.MessageDriven; | ||
import javax.ejb.ActivationConfigProperty; | ||
import org.jboss.seam.jms.example.statuswatcher.model.Status; | ||
import org.jboss.seam.jms.example.statuswatcher.session.StatusManager; | ||
import org.jboss.logging.Logger; | ||
|
||
@MessageDriven(name = "OrderProcessor", activationConfig = { | ||
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), | ||
@ActivationConfigProperty(propertyName = "destination", propertyValue = "/jms/updateStatusQueue") }) | ||
public class DistributorMDB implements MessageListener | ||
{ | ||
@Inject | ||
private Logger log; | ||
|
||
@Inject | ||
private StatusManager manager; | ||
|
||
@Resource(mappedName = "/ConnectionFactory") | ||
private ConnectionFactory connectionFactory; | ||
|
||
@Resource(mappedName = "/jms/statusInfoTopic") | ||
private Topic statusTopic; | ||
|
||
@Override | ||
public void onMessage(Message message) | ||
{ | ||
Connection connection = null; | ||
try | ||
{ | ||
ObjectMessage om = (ObjectMessage) message; | ||
Status status = (Status) om.getObject(); | ||
status = manager.addStatusMessage(status); | ||
connection = connectionFactory.createConnection(); | ||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); | ||
TopicPublisher publisher = ((TopicSession) session).createPublisher(statusTopic); | ||
ObjectMessage update = session.createObjectMessage(status); | ||
publisher.send(update); | ||
} | ||
catch (JMSException e) | ||
{ | ||
log.error(e.getMessage()); | ||
} | ||
finally | ||
{ | ||
if (connection != null) | ||
{ | ||
try | ||
{ | ||
connection.close(); | ||
} | ||
catch (JMSException e) | ||
{ | ||
log.warn("Closing of a connection failed"); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.