[hornetq-commits] JBoss hornetq SVN: r7865 - in trunk: examples/javaee/mdb-message-selector/src/org and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Aug 21 09:17:09 EDT 2009
Author: ataylor
Date: 2009-08-21 09:17:08 -0400 (Fri, 21 Aug 2009)
New Revision: 7865
Added:
trunk/examples/javaee/mdb-message-selector/src/org/hornetq/
trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/
trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/
trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/MDBMessageSelectorClientExample.java
trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/server/
trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/server/MDBMessageSelectorExample.java
Modified:
trunk/hornetq.ipr
Log:
readded mdb selector example
Added: trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/MDBMessageSelectorClientExample.java
===================================================================
--- trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/MDBMessageSelectorClientExample.java (rev 0)
+++ trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/MDBMessageSelectorClientExample.java 2009-08-21 13:17:08 UTC (rev 7865)
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.hornetq.javaee.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class MDBMessageSelectorClientExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = new InitialContext();
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+
+ //Step 3. Perform a lookup on the Connection Factory
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+
+ //Step 4.Create a JMS Connection
+ connection = cf.createConnection();
+
+ //Step 5. Create a JMS Session
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ //Step 6. Create a JMS Message Producer
+ MessageProducer producer = session.createProducer(queue);
+
+ //Step 7. Create a Text Message and set the color property to blue
+ TextMessage blueMessage = session.createTextMessage("This is a text message");
+
+ blueMessage.setStringProperty("color", "BLUE");
+
+ System.out.println("Sent message: " + blueMessage.getText() + " color=BLUE");
+
+ //Step 8. Send the Message
+ producer.send(blueMessage);
+
+ //Step 9. create another message and set the color property to red
+ TextMessage redMessage = session.createTextMessage("This is a text message");
+
+ redMessage.setStringProperty("color", "RED");
+
+ System.out.println("Sent message: " + redMessage.getText() + " color=RED");
+
+ //Step 10. Send the Message
+ producer.send(redMessage);
+ //Step 10,11 and 12 in MDBMessageSelectorExample
+ }
+ finally
+ {
+ //Step 13. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/server/MDBMessageSelectorExample.java
===================================================================
--- trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/server/MDBMessageSelectorExample.java (rev 0)
+++ trunk/examples/javaee/mdb-message-selector/src/org/hornetq/javaee/example/server/MDBMessageSelectorExample.java 2009-08-21 13:17:08 UTC (rev 7865)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.hornetq.javaee.example.server;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+ at MessageDriven(name = "MDBMessageSelectorExample",
+ activationConfig =
+ {
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue"),
+ @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "color = 'RED'")
+ })
+ at TransactionManagement(value= TransactionManagementType.CONTAINER)
+ at TransactionAttribute(value= TransactionAttributeType.REQUIRED)
+public class MDBMessageSelectorExample implements MessageListener
+{
+ public void onMessage(Message message)
+ {
+ try
+ {
+ //Step 11. We know the client is sending a text message so we cast
+ TextMessage textMessage = (TextMessage)message;
+
+ //Step 12. get the text from the message.
+ String text = textMessage.getText();
+
+ //Step 13. We check we received the right color of message
+ String color = textMessage.getStringProperty("color");
+
+ System.out.println("message " + text + " received color=" + color);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/hornetq.ipr
===================================================================
--- trunk/hornetq.ipr 2009-08-21 12:52:42 UTC (rev 7864)
+++ trunk/hornetq.ipr 2009-08-21 13:17:08 UTC (rev 7865)
@@ -287,7 +287,7 @@
</component>
<component name="CopyrightManager" default="">
<copyright>
- <option name="notice" value="Copyright (c) &#36;today.year. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. Vestibulum commodo. Ut rhoncus gravida arcu." />
+ <option name="notice" value="Copyright 2009 Red Hat, Inc. Red Hat licenses this file to you under the Apache License, version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." />
<option name="keyword" value="Copyright" />
<option name="myName" value="new" />
<option name="myLocal" value="true" />
More information about the hornetq-commits
mailing list