Results 1 to 10 of 10

Thread: Error while sending messages with JMS

  1. #1
    Join Date
    Apr 2010
    Posts
    81

    Error while sending messages with JMS

    I am trying to send the message with the JMS but always get an error.!! I think that I may be going wrong while creating directory of the JNDI directory. Because I am not sure how to do it..?! So thought that you guys can help me in this matter. Please tell me everything related to this topic. It would be much better if someone over there provides some sample of coding. Also please tell me how can I create a JNDI context.?!

  2. #2
    Join Date
    Mar 2008
    Posts
    227

    Re: Error while sending messages with JMS

    Creating directory of the JNDI directory
    It uses the JNDI directory flat file of Sun Java System Message Queue. For this, we create the directory containing the file .bindings :
    • mkdir -p /var/imq/imq_admin_objects

    Adding a QueueConnectionFactory in JNDI
    imqobjmgr add -t qf -l cn=QueueConnectionFactory \
    -j java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory \
    -j java.naming.provider.url=file:///var/imq/imq_admin_objects

  3. #3
    Join Date
    Mar 2008
    Posts
    232

    Re: Error while sending messages with JMS

    I am telling you about adding a Queue Queue1 in JNDI.
    imqobjmgr add -tq -l cn=Queue1 \
    -o imqDestinationName=MyQueue \
    -j java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory \
    -j java.naming.provider.url=file:///var/imq/imq_admin_objects
    Here cn=Queue1 refers to the JNDI name of the Queue, namely Queue1. And imqDestinationName=MyQueue means the physical name of the Queue: MyQueue.

  4. #4
    Join Date
    Mar 2008
    Posts
    192

    Re: Create a JNDI context and a JMS connection

    The following code will be helpful for creating a JNDI context and a JMS connection :
    Code:
    import java.util.Hashtable; 
    
    import javax.naming.Context; 
    import javax.naming.InitialContext; 
    
    import javax.naming.NamingException; 
    
    import javax.jms.QueueConnectionFactory; 
    import javax.jms.QueueConnection; 
    
    import javax.jms.JMSException; 
    
    public class JmsSendExample { 
    
    public static final String JNDI_PREFIX = "cn="; 
    public static final String INITIAL_CONTEXT_FACTORY = "com.sun.jndi.fscontext.RefFSContextFactory"; 
    public static final String PROVIDER_URL = "file:///var/imq/imq_admin_objects"; 
    public static final String QUEUE_CONNECTION_FACTORY = "QueueConnectionFactory"; 
    public static final String QUEUE = "Queue1"; 
    
    public static void main(String args[]) { 
    Hashtable env; 
    InitialContext context; 
    QueueConnectionFactory qcf; 
    QueueConnection connection; 
    
    env = new Hashtable(); 
    env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); 
    env.put(Context.PROVIDER_URL, PROVIDER_URL); 
    
    try { 
    context = new InitialContext(env); 
    qcf = (javax.jms.QueueConnectionFactory)context.lookup(JNDI_PREFIX + QUEUE_CONNECTION_FACTORY); 
    connection = qcf.createQueueConnection(); 
    
    ... 
    } 
    catch (javax.naming.NamingException ne) { 
    ne.printStackTrace(); 
    } 
    catch (javax.jms.JMSException jms) { 
    jms.printStackTrace(); 
    } 
    } 
    }

  5. #5
    Join Date
    Dec 2008
    Posts
    161

    Re: Error while sending messages with JMS

    I am trying to illustrate the coding that is given by the "X-Ray".
    • The creation of the JNDI context that corresponds to the JMS provider used: context is an instance of com.sun.jndi.fscontext.RefFSContextFactory , this class implements the interface javax.naming.InitialContext .
    • This context provides a QueueConnectionFactory our Provider (thanks to PROVIDER_URL ) via its JNDI directory.
    • Creating a JMS connection (without specifying the user connection).
    • The parameters declared static variable here are generally the parameters of JMS applications to be portable across different JMS Providers.
    • The Exception javax.naming.NamingException that can be thrown in the instructions using the variable context.

  6. #6
    Join Date
    Dec 2008
    Posts
    183

    Re: Error while sending messages with JMS

    You should also know to create a JMS Session and QueueSender. It adds the following imports:
    import javax.jms.QueueSession;
    import javax.jms.Queue;
    import javax.jms.QueueSender;
    Then:
    QueueSession session;
    Queue queue;
    QueueSender sender;
    Code:
    try { 
    session = connection.createQueueSession(true, 0); 
    queue = (javax.jms.Queue)context.lookup(JNDI_PREFIX + QUEUE); 
    sender = session.createSender(queue); 
    } 
    catch (javax.naming.NamingException ne) { 
    ne.printStackTrace(); 
    } 
    catch (javax.jms.JMSException jms) { 
    jms.printStackTrace(); 
    }

  7. #7
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Error while sending messages with JMS

    In the above coding, you have created the following things :
    • A Session transaction (parameter true ) method createQueueSession . The second parameter createQueueSession is ignored.
    • This method is used and not the method createSession Object Connection to remain portable between versions JMS 1.0.2b and JMS 1.1.
    • An object that represents the JNDI Queue used. Caution, this statement does not create Queue Physics!
    • A QueueSender used in the production of messages. It is typed " Queue "always for reasons of portability.

  8. #8
    Join Date
    Nov 2008
    Posts
    996

    Re: Error while sending messages with JMS

    Create and send a text message JMS
    Code:
     import javax.jms.TextMessage; 
    
    Then: 
    
    TextMessage message; 
    
    try { 
    message = session.createTextMessage("This is a sample JMS message"); 
    sender.send(message); 
    session.commit(); 
    } 
    catch (javax.jms.JMSException jms) { 
    jms.printStackTrace(); 
    }
    Thus:
    • Creates a TextMessage initialized with its contents.
    • Sent the Message with the QueueSender .
    • The message is sent here with the default settings (JMS deliveryMode , priority and timeToLive ).
    • Validated the Session with the order transaction commit.

  9. #9
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Error while sending messages with JMS

    Unlocking the JMS resources. The Java language does not provide free resources allocated. With the JMS API, this is done by method calls close() of some JMS objects. The first object is to release the JNDI context. Closing the JNDI context can be made as soon as all calls to lookup() is performed; unnecessary to wait for the JMS application:
    Code:
     try { 
    context.close(); 
    } 
    catch (javax.naming.NamingException ne) { 
    ne.printStackTrace(); 
    }
    We will then close the Connection JMS as follows:
    Code:
     try { 
    connection.close(); 
    } 
    catch (javax.jms.JMSException jms) { 
    jms.printStackTrace(); 
    }
    The Closing the Connection will automatically close the JMS or Session (s) involved and the subject QueueSender. If you want to be sure that closing the Connection is made systematically, this call connection.close(); can be placed in a block finally to be executed even in case of exception.

  10. #10
    Join Date
    Sep 2010
    Posts
    1

    Re: Error while sending messages with JMS

    Hi Mate
    The JavaNaming Directory Interface palys a vital role with regard to JMS. I suggest you to have clear understanding of concepts and also refer to the Sun's documentation of JNDI.

Similar Threads

  1. Nokia 6220 Classic not sending messages
    By Ishaant Avasthi in forum Portable Devices
    Replies: 5
    Last Post: 30-10-2010, 07:02 PM
  2. BlackBerry messages delayed during Sending and receiving.
    By Takshil in forum Portable Devices
    Replies: 7
    Last Post: 25-09-2010, 10:53 AM
  3. C5 not sending SMS messages but receiving
    By afzal_q in forum Portable Devices
    Replies: 2
    Last Post: 31-07-2010, 01:40 PM
  4. Sending messages to devices on my network.
    By XOIIO in forum Networking & Security
    Replies: 2
    Last Post: 24-12-2009, 09:42 PM
  5. Replies: 2
    Last Post: 19-01-2009, 02:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,632,823.00500 seconds with 17 queries