How will I send messages to Activemq

Hanumath

I never work on JMS. Recently I downloaded Activemq and changed port no from 61616 to 61617 in all conf/activemq-*.xml files.I run the following command from command prompt and open console page on browser.

  C:\Users\Infratab Bangalore\Desktop\Queueing\apache-activemq-5.8.0\bin>activemq

enter image description here

Now I want to send messages from java code using JMS to Activemq.For this I wrote the following code. And run my code using Apache Tomcat server.it's not working

This code is implemented in Eclipse.

package PackageName;

import java.io.IOException;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.ActiveMQConnectionFactory;

public class MessageProducer extends HttpServlet {
    @Override
    protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
        try {
            //created ConnectionFactory object for creating connection 
            ConnectionFactory factory = new ActiveMQConnectionFactory("admin", "admin", "tcp://localhost:61617");
            //Establish the connection
            Connection connection = factory.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue("Test");
            //Added as a producer
            javax.jms.MessageProducer producer = session.createProducer(queue);
            // Create and send the message
            TextMessage msg = session.createTextMessage();
            msg.setText("TestMessage");
            producer.send(msg);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
}

I am getting the following error

 java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
org.apache.activemq.ActiveMQPrefetchPolicy.<clinit>(ActiveMQPrefetchPolicy.java:30)
org.apache.activemq.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:88)
PackageName.MessageProducer.service(MessageProducer.java:20)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

can you suggest me, where I wrote wrong.

Thanks.

Ashish Aggarwal

Download common-logging.ja r file from

http://grepcode.com/snapshot/repo1.maven.org/maven2/commons-logging/commons-logging/1.1.3/

and place this into your classpath and run again.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to re-send ActiveMQ messages that were not acknowledged?

How to rollback messages in Activemq

Unable to create producer to send messages on ActiveMQ

ActiveMQ: how to dequeue older messages?

How to catch unexpected messages in c#, while I send messages and I also want to accept answers for the messages?

How to send email using activemq

How to send XML file to ActiveMQ?

How to send OTA messages?

pyTelegramBotAPI - how to send the messages

How do I send/receive multicast messages using MSMQ?

How can I show notify-send messages triggered by crontab?

How can I send a Flux of messages as individual requests using WebClient?

How do I send periodic messages to connected clients of a Websocket in Perl

How i send big messages faster in python socket?

How do I send messages to idle akka actors?

How can I configure logback conf to send all messages to stderr?

How do I send & receives Telegram messages programmatically?

How can I send IoT hub messages to MQTT broker?

How can I send messages to specific client using Faye Websockets?

How can I fix `DiscordAPIError: Cannot send messages to this user`?

how do i make my bot send random messages as a DM

How can I send messages to my private telegram channel with Telethon?

ActiveMQ 5.11.1 Constantly throws EOFException and Won't Send Messages

In Apache ActiveMQ Artemis, how can I force Stomp messages to be text instead of binary?

How consume messages in specific sequence in ActiveMQ?

How clean activemq queue when messages are not cunsumed

How do I know the details of which messages failed to send when using MassTransit SendBatch method to send multiple messages in one go?

how do i send a message to a ActiveMQ using JMS Sender in wso2esb

How to send large files to ActiveMQ using camel