<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Hello World AS JMS - URGENT!
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/nirajpatel">Niraj Patel</a> in <i>Beginner's Corner</i> - <a href="https://community.jboss.org/docs/DOC-48891">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p><span style="font-size: 12pt;"><strong>Hi,</strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 12pt;"><strong>I am very new to jBoss and I have a client deadline of tomorrow to show a working example of our product using jBoss.I cannot for the life of me figure out how to run the Hello World AS JMS example provided by jboss on my computer. I want to deploy it and obtain the messages as well. How do I do that? Or must I have 2 seperate computers? Please provide a detailed explanation.</strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-size: 12pt;"><strong>THANK YOU!</strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>--------</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>/*</p><p> * JBoss, Home of Professional Open Source</p><p> * Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual</p><p> * contributors by the @authors tag. See the copyright.txt in the </p><p> * distribution for a full listing of individual contributors.</p><p> *</p><p> * Licensed under the Apache License, Version 2.0 (the "License");</p><p> * you may not use this file except in compliance with the License.</p><p> * You may obtain a copy of the License at</p><p><span> * </span><a class="jive-link-external-small" href="http://www.apache.org/licenses/LICENSE-2.0" rel="nofollow" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a></p><p> * Unless required by applicable law or agreed to in writing, software</p><p> * distributed under the License is distributed on an "AS IS" BASIS,&#160; </p><p> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</p><p> * See the License for the specific language governing permissions and</p><p> * limitations under the License.</p><p> */</p><p>package org.jboss.as.quickstarts.jms;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import java.util.logging.Logger;</p><p>import java.util.Properties;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import javax.jms.Connection;</p><p>import javax.jms.ConnectionFactory;</p><p>import javax.jms.Destination;</p><p>import javax.jms.MessageConsumer;</p><p>import javax.jms.MessageProducer;</p><p>import javax.jms.Session;</p><p>import javax.jms.TextMessage;</p><p>import javax.naming.Context;</p><p>import javax.naming.InitialContext;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class HelloWorldJMSClient {</p><p>&#160;&#160;&#160; private static final Logger log = Logger.getLogger(HelloWorldJMSClient.class.getName());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; // Set up all the default values</p><p>&#160;&#160;&#160; private static final String DEFAULT_MESSAGE = "Hello, World!";</p><p>&#160;&#160;&#160; private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";</p><p>&#160;&#160;&#160; private static final String DEFAULT_DESTINATION = "jms/queue/test";</p><p>&#160;&#160;&#160; private static final String DEFAULT_MESSAGE_COUNT = "1";</p><p>&#160;&#160;&#160; private static final String DEFAULT_USERNAME = "quickstartUser";</p><p>&#160;&#160;&#160; private static final String DEFAULT_PASSWORD = "quickstartPassword";</p><p>&#160;&#160;&#160; private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";</p><p>&#160;&#160;&#160; private static final String PROVIDER_URL = "remote://localhost:4447";</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public static void main(String[] args) throws Exception {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConnectionFactory connectionFactory = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Connection connection = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Session session = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MessageProducer producer = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MessageConsumer consumer = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Destination destination = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TextMessage message = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Context context = null;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Set up the context for the JNDI lookup</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final Properties env = new Properties();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context = new InitialContext(env);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Perform the JNDI lookups</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String destinationString = System.getProperty("destination", DEFAULT_DESTINATION);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("Attempting to acquire destination \"" + destinationString + "\"");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; destination = (Destination) context.lookup(destinationString);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("Found destination \"" + destinationString + "\" in JNDI");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Create the JMS connection, session, producer, and consumer</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection = connectionFactory.createConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; producer = session.createProducer(destination);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; consumer = session.createConsumer(destination);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection.start();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String content = System.getProperty("message.content", DEFAULT_MESSAGE);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("Sending " + count + " messages with content: " + content);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Send the specified number of messages</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (int i = 0; i &lt; count; i++) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; message = session.createTextMessage(content);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; producer.send(message);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Then receive the same number of messaes that were sent</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (int i = 0; i &lt; count; i++) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; message = (TextMessage) consumer.receive(5000);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info("Received message with content " + message.getText());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (Exception e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.severe(e.getMessage());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw e;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } finally {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (context != null) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // closing the connection takes care of the session, producer, and consumer</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (connection != null) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p><p>}</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="https://community.jboss.org/docs/DOC-48891">going to Community</a></p>

        <p style="margin: 0;">Create a new document in Beginner's Corner at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2075">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>