switch Tibco RV to WebSphere MQ? - java

My application is listening to Tibco RV, now I am required to switch to WebSphere MQ. I found the code like this
Tibrv.open(Tibrv.IMPL_NATIVE);
rvdTransport = new TibrvRvdTransport(...);
TibrvQueue queue = new TibrvQueue();
cmqTransport = new TibrvCmQueueTransport(...);
queueListener = new TibrvCmListener(...);
disp = new TibrvDispatcher(...)
In the MQ side, do we have similar concepts?
Thanks

Short answer - Yes.
When you download and install the WMQ client (SupportPac MQC71) you get, in addition to the Java classes, diagnostic utilities and lots of sample code. Among the sample programs you will find MQSample.java which looks like this:
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.MQConstants;
public class MQSample {
public static void main(String args[]) {
try {
// Create a connection to the QueueManager
System.out.println("Connecting to queue manager: " + qManager);
MQQueueManager qMgr = new MQQueueManager(qManager);
// Set up the options on the queue we wish to open
int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT;
// Now specify the queue that we wish to open and the open options
System.out.println("Accessing queue: " + qName);
MQQueue queue = qMgr.accessQueue(qName, openOptions);
// Define a simple WebSphere MQ Message ...
MQMessage msg = new MQMessage();
// ... and write some text in UTF8 format
msg.writeUTF("Hello, World!");
// Specify the default put message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
// Put the message to the queue
System.out.println("Sending a message...");
queue.put(msg, pmo);
// Now get the message back again. First define a WebSphere MQ
// message
// to receive the data
MQMessage rcvMessage = new MQMessage();
// Specify default get message options
MQGetMessageOptions gmo = new MQGetMessageOptions();
// Get the message off the queue.
System.out.println("...and getting the message back again");
queue.get(rcvMessage, gmo);
// And display the message text...
String msgText = rcvMessage.readUTF();
System.out.println("The message is: " + msgText);
// Close the queue
System.out.println("Closing the queue");
queue.close();
// Disconnect from the QueueManager
System.out.println("Disconnecting from the Queue Manager");
qMgr.disconnect();
System.out.println("Done!");
}
catch (MQException ex) {
System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode
+ " Reason Code " + ex.reasonCode);
ex.printStackTrace();
for (Throwable t = ex.getCause(); t != null; t = t.getCause()) {
System.out.println("... Caused by ");
t.printStackTrace();
}
}
catch (java.io.IOException ex) {
System.out.println("An IOException occured whilst writing to the message buffer: " + ex);
}
return;
}
}
There are of course also samples for JMS, C, C#, etc. The sample shown uses synchronous (blocking) GET calls but there are async listener methods if you want to implement with a callback mechanism.
I would also recommend looking over the application development sections of the Infocenter. These are the v7.0 docs and these are the v7.1 docs.

Related

Need a sample Request(Java)-Reply(C++) example in solace.

import com.solacesystems.jcsmp.BytesXMLMessage;
import com.solacesystems.jcsmp.JCSMPException;
import com.solacesystems.jcsmp.JCSMPFactory;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.JCSMPRequestTimeoutException;
import com.solacesystems.jcsmp.JCSMPSession;
import com.solacesystems.jcsmp.JCSMPStreamingPublishEventHandler;
import com.solacesystems.jcsmp.Requestor;
import com.solacesystems.jcsmp.TextMessage;
import com.solacesystems.jcsmp.Topic;
import com.solacesystems.jcsmp.XMLMessageConsumer;
import com.solacesystems.jcsmp.XMLMessageListener;
import com.solacesystems.jcsmp.XMLMessageProducer;
public class REquestor {
public static void main(String... args) throws JCSMPException {
// Check command line arguments
String host="tcp://52.76.233.76:55555";
String username="ccs_jcsmp_user_ccs3";
String pwd="password";
String vpn="default";
System.out.println("BasicRequestor initializing...");
// Create a JCSMP Session
final JCSMPProperties properties = new JCSMPProperties();
properties.setProperty(JCSMPProperties.HOST, host); // host:port
properties.setProperty(JCSMPProperties.USERNAME, username); // client-username
properties.setProperty(JCSMPProperties.PASSWORD, pwd); // client-password
properties.setProperty(JCSMPProperties.VPN_NAME, vpn); // message-vpn
final JCSMPSession session = JCSMPFactory.onlyInstance().createSession(properties);
session.connect();
//This will have the session create the producer and consumer required
//by the Requestor used below.
/** Anonymous inner-class for handling publishing events */
#SuppressWarnings("unused")
XMLMessageProducer producer = session.getMessageProducer(new JCSMPStreamingPublishEventHandler() {
public void responseReceived(String messageID) {
System.out.println("Producer received response for msg: " + messageID);
}
public void handleError(String messageID, JCSMPException e, long timestamp) {
System.out.printf("Producer received error for msg: %s#%s - %s%n",
messageID,timestamp,e);
}
});
XMLMessageConsumer consumer = session.getMessageConsumer((XMLMessageListener)null);
// final XMLMessageConsumer consumer = session.getMessageConsumer(new XMLMessageListener() {
//
// public void onReceive(BytesXMLMessage reply) {
//
// System.out.printf("TextMessage reply received: '%s'%n",((TextMessage)reply).getText());
//
// }
//
// public void onException(JCSMPException e) {
// System.out.printf("Consumer received exception: %s%n", e);
// }
// });
// consumer.
consumer.start();
final Topic topic = JCSMPFactory.onlyInstance().createTopic("topicAnkit");
//Time to wait for a reply before timing out
final int timeoutMs = 100000;
TextMessage request = JCSMPFactory.onlyInstance().createMessage(TextMessage.class);
final String text = "Sample Request from Java!";
request.setText(text);
try {
Requestor requestor = session.createRequestor();
System.out.printf("Connected. About to send request message '%s' to topic '%s'...%n",text,topic.getName());
BytesXMLMessage reply = requestor.request(request, timeoutMs, topic);
// Process the reply
if (reply instanceof TextMessage) {
System.out.printf("TextMessage response received: '%s'%n",
((TextMessage)reply).getText());
}
System.out.printf("Response Message Dump:%n%s%n",reply.dump());
} catch (JCSMPRequestTimeoutException e) {
System.out.println("Failed to receive a reply in " + timeoutMs + " msecs");
}
System.out.println("Exiting...");
session.closeSession();
}
}
So my requirement is I am going to send message to "TopicAnkit" and listen for response in some topic/queue "topicResponse". How to achieve this?
I see in my C++ replier I receive the request and send the reply to this program but this Java Requester is not listening to any topics.
I see a temp topic is created in sendTo field to requester and sending is success but requester not getting the response.
Please advice
1. How to get the response in Java requester from this temp topic
2. How to specify a listening topic so that C++ can send the response to this topic.
Thanks
Ankit
You don't seem to be explicitly setting which reply topic you want to use.
It can either be set on the message, or on the session, see https://docs.solace.com/API-Developer-Online-Ref-Documentation/java/com/solacesystems/jcsmp/Requestor.html
Add
final Topic responseTopic = JCSMPFactory.onlyInstance().createTopic("responseTopic");
request.setReplyTo(responseTopic);
before sending the message
Check message CorrelationId and ReplyTo.
As per solace API documentation don't forget about "#":
Requestor uses CorrelationId values starting with '#' which are reserved for internal use such as two party request/reply. If other applications are required to receive the reply, specify an application CorrelationId.

Trouble trying to consume persistent messages on Tibco EMS with selectors in Java (JMS)

So I'm trying to consume messages from a Tibco EMS broker via JMS with a message Id selector. If messages are NON_PERSISTENT, I can select them by their JMSMessageID's, and all works fine.
If the messages are PERSISTENT, the selector doesn't retrieve anything. I've tried the same code on Apache ActiveMQ, and it works in both cases. I've been through the EMS samples and cant see anything obvious. Wondering if there's some EMS settings that might affect this...
If I omit the selector, then messages are properly consumed regardless of DeliveryMode.
Here's what I'm using to reproduce it.
Any help would be much appreciated :)
package com;
import javax.jms.*;
import com.tibco.tibjms.TibjmsConnectionFactory;
public class JMSTest {
String msgIdPersistent = "";
String msgIdNon_Persistent = "";
String serverUrl = "tcp://localhost:7222";
String queueName = "test";
public static void main(String[] args) {
JMSTest test = new JMSTest();
try {
test.publish();
test.deleteBySelector();
}catch(Exception ex) {
ex.printStackTrace();
}
}
public void deleteBySelector() throws Exception {
// Create connection and session
ConnectionFactory factory = new TibjmsConnectionFactory(serverUrl);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession();
// Delete non-persistent
//
String selectorNonPersist = "JMSMessageID='" + msgIdNon_Persistent + "'";
MessageConsumer nonPersistReceiver = session.createConsumer(session.createQueue(queueName), selectorNonPersist);
Message nonPersistMsg = null;
nonPersistMsg = nonPersistReceiver.receive(1000);
System.out.println("NON PERSISTENT SELECTOR: " + ((nonPersistMsg!=null) ? "SUCCESS" : "FAIL"));
// Delete Persistent - **** THIS DOESN'T WORK *****
//
String selectorPersist = "JMSMessageID='" + msgIdPersistent + "'";
MessageConsumer persistReceiver = session.createConsumer(session.createQueue(queueName), selectorPersist);
Message persistMsg = null;
persistMsg = persistReceiver.receive(1000);
System.out.println("PERSISTENT SELECTOR: " + ((persistMsg!=null) ? "SUCCESS" : "FAIL"));
}
public void publish() throws Exception {
ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(serverUrl);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(javax.jms.Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("test");
// Send persistent message
//
System.out.println("Persistent publish");
MessageProducer producerPersistent = session.createProducer(null);
producerPersistent.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage messagePersistent = session.createTextMessage("PERSISTENT");
producerPersistent.send(destination, messagePersistent);
msgIdPersistent = messagePersistent.getJMSMessageID();
System.out.println("\tMsgId=" + msgIdPersistent);
// Send Non Persistent message
//
System.out.println("NON Persistent publish");
MessageProducer producernonPersistent = session.createProducer(destination);
producernonPersistent.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage messageNonPersistent = session.createTextMessage("NON_PERSISTENT");
producernonPersistent.send(messageNonPersistent);
msgIdNon_Persistent = messageNonPersistent.getJMSMessageID();
System.out.println("\tMsgId=" + msgIdNon_Persistent);
// Clean up
session.close();
connection.close();
System.out.println("Done publish\n");
}
}
The output I'm getting from this is:
Persistent publish
MsgId=ID:EMS-SERVER.3D856ECE827932:1
NON Persistent publish
MsgId=ID:EMS-SERVER.3D856ECE827932:2
Done publish
NON PERSISTENT SELECTOR: SUCCESS
PERSISTENT SELECTOR: FAIL
I've confirmed its a bug in 8.2.x. I upgraded to 8.3.x and it is working fine.

Use multiple gateway with SMSLIB

I want use multiple gateway to send messages with SMSLIB.
I have 4 HSPA modems and for each one a different operator, how to detect the name of operator and from there using a specific SMS to be sent.
Here my code:
// SendMessage.java - Sample application.
//
// This application shows you the basic procedure for sending messages.
// You will find how to send synchronous and asynchronous messages.
//
// For asynchronous dispatch, the example application sets a callback
// notification, to see what's happened with messages.
package sms;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
public class SendMessage
{
public void doIt() throws Exception
{
OutboundNotification outboundNotification = new OutboundNotification();
System.out.println("Example: Send message from a serial gsm modem.");
System.out.println(Library.getLibraryDescription());
System.out.println("Version: " + Library.getLibraryVersion());
SerialModemGateway gateway = new SerialModemGateway("modem.com3", "COM3", 115200, "Huawei", "");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
// Explicit SMSC address set is required for some modems.
// Below is for VODAFONE GREECE - be sure to set your own!
gateway.setSmscNumber("+947500001");
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
System.out.println();
System.out.println("Modem Information:");
System.out.println(" Manufacturer: " + gateway.getManufacturer());
System.out.println(" Model: " + gateway.getModel());
System.out.println(" Serial No: " + gateway.getSerialNo());
System.out.println(" SIM IMSI: " + gateway.getImsi());
System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("0094757599108", "Hello from SMSLib!");
Service.getInstance().sendMessage(msg);
System.out.println(msg);
// Or, send out a WAP SI message.
//OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000", new URL("http://www.smslib.org/"), "Visit SMSLib now!");
//Service.getInstance().sendMessage(wapMsg);
//System.out.println(wapMsg);
// You can also queue some asynchronous messages to see how the callbacks
// are called...
//msg = new OutboundMessage("309999999999", "Wrong number!");
//srv.queueMessage(msg, gateway.getGatewayId());
//msg = new OutboundMessage("308888888888", "Wrong number!");
//srv.queueMessage(msg, gateway.getGatewayId());
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
Service.getInstance().stopService();
}
public class OutboundNotification implements IOutboundMessageNotification
{
public void process(AGateway gateway, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
System.out.println(msg);
}
}
public static void main(String args[])
{
SendMessage app = new SendMessage();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
This one detect only one gateway from COM3, but i have a USB SWITCHER in COM3 and 4 modems on it.
What is the method to use to get them detected (I want a method to do it), thank you so much.

How to write a sender application for ActiveMQ in Node JS

I wanted to create implement a JMS sender app for messaging and created the same with JAVA. This is my sample code snippet in Java.
try {
factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
connection = factory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue("SAMPLEQUEUE");
producer = session.createProducer(destination);
try {
TextMessage message = session.createTextMessage();
message.setText("hello");
producer.send(message);
System.out.println("Sent: " + message.getText());
} catch (IOException e) {
e.printStackTrace();
}
} catch (JMSException e) {
e.printStackTrace();
}
This works fine and I am able to receive the messages with my receiver also. I want to change the sender implementation in Node JS and make it a Node JS application. I am new to Node JS didn't understand much after searching on ActiveMQ in Node JS. Any pointer to it would be really helpful.
Regards,
Subhankar
EDIT
I used stomp for node JS. The sample code is the following :
var Stomp = require('stomp-client');
var destination = '/queue/sensorstreamqueue';
var client = new Stomp('10.53.219.153', 61613, 'user', 'pass');
var lazy = require("lazy"),
fs = require("fs");
client.connect(function(sessionId) {
new lazy(fs.createReadStream('input.csv'))
.lines
.forEach(function(line){
client.publish(destination, line.toString());
}
);
console.log("published");
});
The code works and my receiver also gets the message but then my receiver expects it to be a textMesssage format and gives the following error:
02-19-2015 08:42:31.288 ERROR [Thread-25] (JmsInputTransporter.handleTextMessage) Error code:401306, Severity : 3 (Error)
Error message:JMS Transporter is expected a TextMessage, received class org.apache.activemq.command.ActiveMQBytesMessage.
Error description:JMS Transporter is expected a TextMessage, received class org.apache.activemq.command.ActiveMQBytesMessage.
Can someone help me how can I achieve that?
You can try the activemq-node module, or you can enable the STOMP protocol on ActiveMQ and use this node.js library.
You need to add a header:
client.publish(destination, 'your content', {
"amq-msg-type": "text"
});
https://issues.apache.org/jira/browse/AMQ-2833

ActiveMQ KahaDB always locking and waiting

I am trying to use ActiveMQ in a relatively simple work queue use case. I have one queue, and have a simple Producer and Consumer.
My question is what am I doing wrong that continuously makes the DB lock?
here is the message I get continously:
14/04/05 18:14:13 INFO store.SharedFileLocker: Database activemq-data\localhost\KahaDB\lock is locked... waiting 10 seconds for the database to be unlocked. Reason: java.io.IOException: File 'activemq-data\localhost\KahaDB\lock' could not be locked.
I am running the producer and consumer in separate threads at the same time.
Initially, I had the connection at the class level, so I thought that was the problem, but even creating the connection from scratch every call to put and get still causes locking.
I have done research but have failed to find a solution.
I am running ActiveMQ 5.9.0 on windows 7.
Here is what prints out when I start it via cmd prompt:
C:\activemq\apache-activemq-5.9.0\bin>activemq
Java Runtime: Oracle Corporation 1.7.0_40 C:\Program Files\Java\jre7
Heap sizes: current=1005568k free=995061k max=1005568k
JVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Dhawtio.realm=activemq -Dhawtio.role=admins -Dhawtio.rolePrincipalCla
vemq.jaas.GroupPrincipal -Djava.security.auth.login.config=C:\activemq\apache-activemq-5.9.0\bin\..\conf\login.config -Dactivemq.classpath=C:\activemq\apache-activemq-5.9.0\bin\..\
che-activemq-5.9.0\bin\../conf;C:\activemq\apache-activemq-5.9.0\bin\../conf; -Dactivemq.home=C:\activemq\apache-activemq-5.9.0\bin\.. -Dactivemq.base=C:\activemq\apache-activemq-5
mq.conf=C:\activemq\apache-activemq-5.9.0\bin\..\conf -Dactivemq.data=C:\activemq\apache-activemq-5.9.0\bin\..\data -Djava.io.tmpdir=C:\activemq\apache-activemq-5.9.0\bin\..\data\t
Extensions classpath:
[C:\activemq\apache-activemq-5.9.0\bin\..\lib,C:\activemq\apache-activemq-5.9.0\bin\..\lib\camel,C:\activemq\apache-activemq-5.9.0\bin\..\lib\optional,C:\activemq\apache-activemq
b,C:\activemq\apache-activemq-5.9.0\bin\..\lib\extra]
ACTIVEMQ_HOME: C:\activemq\apache-activemq-5.9.0\bin\..
ACTIVEMQ_BASE: C:\activemq\apache-activemq-5.9.0\bin\..
ACTIVEMQ_CONF: C:\activemq\apache-activemq-5.9.0\bin\..\conf
ACTIVEMQ_DATA: C:\activemq\apache-activemq-5.9.0\bin\..\data
Loading message broker from: xbean:activemq.xml
INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1#5bf2a8f5: startup date [Sat Apr 05 17:42:42 EDT 2014]; root of context hierarchy
INFO | PListStore:[C:\activemq\apache-activemq-5.9.0\bin\..\data\localhost\tmp_storage] started
INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\activemq\apache-activemq-5.9.0\bin\..\data\kahadb]
INFO | KahaDB is version 5
INFO | Recovering from the journal ...
INFO | Recovery replayed 6935 operations from the journal in 0.416 seconds.
INFO | Apache ActiveMQ 5.9.0 (localhost, ID:Owner-PC-49614-1396734165637-0:1) is starting
INFO | Listening for connections at: tcp://Owner-PC:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector openwire started
INFO | Listening for connections at: amqp://Owner-PC:5673?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector amqp started
INFO | Listening for connections at: stomp://Owner-PC:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector stomp started
INFO | Listening for connections at: mqtt://Owner-PC:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector mqtt started
INFO | Listening for connections at ws://Owner-PC:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600
INFO | Connector ws started
INFO | Apache ActiveMQ 5.9.0 (localhost, ID:Owner-PC-49614-1396734165637-0:1) started
INFO | For help or more information please see: http://activemq.apache.org
INFO | Welcome to hawtio 1.2-M23 : http://hawt.io/ : Don't cha wish your console was hawt like me? ;-)
INFO | Starting hawtio authentication filter, JAAS realm: "activemq" authorized role: "admins" role principal classes: "org.apache.activemq.jaas.GroupPrincipal"
INFO | Using file upload directory: C:\activemq\apache-activemq-5.9.0\bin\..\data\tmp\uploads
INFO | jolokia-agent: Using access restrictor classpath:/jolokia-access.xml
INFO | ActiveMQ WebConsole available at http://localhost:8161/
INFO | Initializing Spring FrameworkServlet 'dispatcher'
Here is my java to implement the Queue as ActiveMQ (I have a Queue interface and this is an Impl)
import com.google.gson.Gson;
import java.util.Set;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
public class ActiveMQImpl implements Queue, ExceptionListener {
private String host;
private String user;
private String pw;
public void init() {
}
public void close() {
}
public Message get() {
Message outMessage = null;
ActiveMQConnectionFactory connectionFactory = null;
Connection connection = null;
try {
if (connection == null) {
connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
// Create a Connection
connection = connectionFactory.createConnection();
}
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("work");
// Create a MessageConsumer from the Session to the Topic or Queue
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
javax.jms.Message message = consumer.receive(1000);
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
outMessage = new Gson().fromJson(text, Message.class);
// System.out.println("Received: " + text);
} else {
// System.out.println("Received: " + message);
}
consumer.close();
// session.commit();
session.close();
//connection.close();
} catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
return outMessage;
}
public void put(Message inMessage) {
try {
ActiveMQConnectionFactory connectionFactory = null;
Connection prodConnection = null;
connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
prodConnection = connectionFactory.createConnection();
prodConnection.start();
Session session = prodConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("work");
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
producer.setTimeToLive(60000);
// Create a messages
String text = inMessage.toString();
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
System.out.println("Sent message: " + text);
producer.send(message);
producer.close();
// session.commit();
session.close();
prodConnection.close();
} catch (Exception e) {
System.out.println("Caught: " + e);
onException(null);
e.printStackTrace();
}
}
public void onException(JMSException jmse) {
//send this to the error channel object...
System.out.println(jmse);
}
public void put(Set<Message> messages) {
try {
ActiveMQConnectionFactory connectionFactory=null;
Connection connection=null;
Connection prodConnection=null;
if (connection == null) {
connectionFactory = new ActiveMQConnectionFactory("vm://localhost?jms.useAsyncSend=true");
// Create a Connection
connection = connectionFactory.createConnection("admin", "admin");
}
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("work");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
// Create a messages
for (Message inMessage : messages) {
String text = inMessage.toString();
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
System.out.println("Sent message: " + text);
producer.send(message);
}
producer.close();
// session.commit();
session.close();
//connection.close();
} catch (Exception e) {
System.out.println("Caught: " + e);
onException(null);
e.printStackTrace();
}
}
}
Here are the producers and consumers (simple debugging classes)
public class Producer {
public static void main(String[] args) {
Queue q = QueueFactory.create(QueueType.ACTIVEMQ);
try {
for (int i = 0; i < 10; i++) {
q.put(new Message("testimpl" + i, "whatever", i));
Thread.sleep(1000);
}
} catch (InterruptedException ex) {
Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public class Consumer {
public static void main(String[] args) {
Queue q = QueueFactory.create(QueueType.ACTIVEMQ);
try {
while (true) {
Message get = q.get();
System.out.println(get);
Thread.sleep(1000);
}
} catch (InterruptedException ex) {
Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
any help is appreciated.
do following
kill java process for active mq, open task manager -> go to process -> check for java -> and right click and say end process
then go to <activemq_install_directory>/data/kahadb
and delete lock file which gets generated
try starting activemq again
for me this works every time I face this issue
had the same problem.
there was no other java services / brokers up and running.
the problem was pretty stupid -
make sure that the user you are using has permission to write to the path of the lock file.
The only solution I came across to release this lock is-
Goto services.msc
Stop ActiveMQ forever (let StartUp type be Automatic)
you will see that the lock file disappears
delete the datafolder itself
Restart apache-activemq-5.10.0-bin\apache-activemq-5.10.0\bin\win64\activemq.bat (Not services.msc)
You are good to go
for linux just:
sudo killall java
and start again

Categories

Resources