Search code examples
javajmsjboss7.xapache-servicemix

Connection with JMS (Apacher ServiceMix) from jboss 7.1


I have a web application deployed in a jboss 7.1 that must send messages to a JMS QUEUE implemented in an apacheServiceMix 6.1.0.

Whenever i want to send a message i get this error:

Exception in thread "JMX connector" java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only

I'm not sure if it's a configuration problem or something with my code.

ConnectionFactory factory = null;

try{
    factory = new ActiveMQConnectionFactory(jmsUser, jmsPassword, jmsUrl);
    Producer producer = new Producer(factory, jmsQueue);
    Map<String, String> mapMessage = new HashMap<String, String>();
    mapMessage.put("From", "[email protected]");
    mapMessage.put("to","mailTo");
    mapMessage.put("subject", "Subject");
    mapMessage.put("template", "template.vm");
    mapMessage.put("user", "username");
    mapMessage.put("link", "link");

    producer.getMessages().add(mapMessage);

    producer.run();
    producer.close();

} catch (Exception e){
    LOG.error(e.getMessage(), e);
}

Producer.java

public class Producer{

private ConnectionFactory factory;
private Connection connection;
private Session session;
private MessageProducer producer;
private List<Map<String, String>> messages;

public Producer(ConnectionFactory factory, String queueName) throws JMSException
{
    this.factory = factory;
    connection = factory.createConnection();
    connection.start();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(queueName);
    producer = session.createProducer(destination);
}

public void run() throws JMSException
{
    for(Map<String, String> mapMessage : messages){
        ObjectMessage message = session.createObjectMessage();
        for (Map.Entry<String, String> entry : mapMessage.entrySet()){
            message.setStringProperty(entry.getKey(), entry.getValue());
        }
        producer.send(message);
    }        
}

public void close() throws JMSException
{
    if (connection != null)
    {
        connection.close();
    }
}

public List<Map<String, String>> getMessages() {
    if(messages == null){
        messages = new ArrayList<Map<String, String>>();
    }
    return messages;
}

public void setMessages(List<Map<String, String>> messages) {
    this.messages = messages;
}

}

i've try to start jboss with -Dorg.apache.activemq.broker.jmx.createConnector=false param with same result.

any clue?


Solution

  • i've been able to workaround this.

    I was using vm (url vm:// )protocol, when i changed it to tcp tcp://:61616 it worked like a charm.