<!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="http://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;">
JBoss Settings for MDB Client ?
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/shptlucky">shptlucky</a> in <i>JBoss Messaging</i> - <a href="http://community.jboss.org/message/603174#603174">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>I have made message driven bean. </p><p>I have made a producer class.</p><p>I am using Netbeans</p><p>Producer Class is sending message to local host and i am recieving it.</p><p>but i am not getting settings to be done for remote connection.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I am striving for last three weeks on it. Please anyone help and tell me what settings is required on client side or server for Remote JMS message retrieving. Code is here under:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>For Sending</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>package com;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import java.util.Hashtable;</p><p>import javax.naming.Context;</p><p>import javax.naming.InitialContext;</p><p>import javax.naming.NamingException;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import javax.jms.TopicConnectionFactory;</p><p>import javax.jms.TopicConnection;</p><p>import javax.jms.TopicSession;</p><p>import javax.jms.TopicPublisher;</p><p>import javax.jms.Topic;</p><p>import javax.jms.TextMessage;</p><p>import javax.jms.Session;</p><p>import javax.jms.JMSException;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>/**</p><p> * <p>Simple JMS client, publish text messages to testTopic Topic.</p><p> * </p></p><p> *</p><p> * <p><b>NOTE</b>This code is a showcase only. It may not provide</p><p> * a stable production example.</p></p><p> * @author Peter Antman</p><p> * @version $Revision: 3.1 $</p><p> */</p><p>public class NewClass {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Topic connection, hold on to this so you may close it.</p><p>     */</p><p>    TopicConnection topicConnection;</p><p>    /**</p><p>     * Topic session, hold on to this so you may close it.</p><p>     * Also used to create messages.</p><p>     */</p><p>    TopicSession topicSession;</p><p>    /**</p><p>     * Use this to publish messages.</p><p>     */</p><p>    TopicPublisher topicPublisher;</p><p>    /**</p><p>     * Destination where to publish.</p><p>     */</p><p>    Topic topic;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Sets up all the JMS fixtures.</p><p>     *</p><p>     * Use close() when finished with object.</p><p>     *</p><p>     * @param factoryJNDI name of the topic connection factory to look up.</p><p>     * @param topicJNDI name of the topic destination to look up</p><p>     */</p><p>    public NewClass(String factoryJNDI, String topicJNDI)</p><p>            throws JMSException, NamingException {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Populate with needed properties</p><p>            Hashtable props = new Hashtable();</p><p>            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");</p><p>            props.put(Context.PROVIDER_URL, "192.168.1.218:1099");</p><p>            props.put("java.naming.rmi.security.manager", "yes");</p><p>            props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // Get the initial context with given properties</p><p>            Context context = new InitialContext(props);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            System.out.println(factoryJNDI);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Get the initial context</p><p>       // Context context = new InitialContext();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Get the connection factory</p><p>        TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup("java:/XAConnectionFactory");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Create the connection</p><p>        topicConnection = topicFactory.createTopicConnection();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Create the session</p><p>        topicSession = topicConnection.createTopicSession(</p><p>                // No transaction</p><p>                false,</p><p>                // Auto ack</p><p>                Session.AUTO_ACKNOWLEDGE);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Look up the destination</p><p>        topic = (Topic) context.lookup(topicJNDI);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Create a publisher</p><p>        topicPublisher = topicSession.createPublisher(topic);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Publish the given String as a JMS message to the testTopic topic.</p><p>     */</p><p>    public void publish(String msg) throws JMSException {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Create a message</p><p>        TextMessage message = topicSession.createTextMessage();</p><p>        message.setText(msg);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Publish the message</p><p>        topicPublisher.publish(topic, message);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Close session and connection.</p><p>     * When done, no publishing is possible any more.</p><p>     */</p><p>    public void close() throws JMSException {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        topicSession.close();</p><p>        topicConnection.close();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    /**</p><p>     * Run an example publishing 10 messages to testTopic.</p><p>     * Only works up to and including JBoss 2.4.0</p><p>     */</p><p>    public static void main(String[] args) {</p><p>        try {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // Create the HelloPublisher, giving it the name of the</p><p>            // TopicConnection Factory and the Topic destination to</p><p>            // use in lookup.</p><p>            NewClass publisher = new NewClass("ConnectionFactory","topic/testTopic1");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // Publish 10 messages</p><p>            for (int i = 1; i < 11; i++) {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                String msg = "Hello World no. " + i;</p><p>                System.out.println("Publishing message: " + msg);</p><p>                publisher.publish(msg);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // Close down your publisher</p><p>            publisher.close();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        }</p><p>        catch (Exception ex)</p><p>        {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            System.err.println("An exception occurred while testing HelloPublisher: " + ex);</p><p>            ex.printStackTrace();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    }</p><p>} // HelloPublisher</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>MDB For reciving on Client End</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>package com;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import java.util.logging.Level;</p><p>import java.util.logging.Logger;</p><p>import javax.ejb.ActivationConfigProperty;</p><p>import javax.ejb.MessageDriven;</p><p>import javax.jms.JMSException;</p><p>import javax.jms.Message;</p><p>import javax.jms.MessageListener;</p><p>import javax.jms.TextMessage;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@MessageDriven(mappedName = "topic/testTopic", </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    activationConfig =  {</p><p>        @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/testTopic"),</p><p>        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),</p><p>        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),</p><p>        @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "NonDurable"),</p><p>        @ActivationConfigProperty(propertyName = "clientId", propertyValue = "DrivenBean6"),</p><p>        @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "DrivenBean6")</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                        })</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>public class DrivenBean implements MessageListener {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    public DrivenBean() {</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>     TextMessage tx=null;</p><p>    public void onMessage(Message message)</p><p>    {</p><p>        tx=(TextMessage) message;</p><p>        try {</p><p>            System.out.println("Driven Bean -> " + tx.getText());</p><p>        } catch (JMSException ex) {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        }</p><p>        System.out.println("Hello");</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>What Settings are required so that i could send message to client end.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/603174#603174">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Messaging at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>