I need to send JMS messages to the following provider location:
failover:(tcp://amq.vip.ebay.com:61616,tcp://amqstby.vip.ebay.com:61616)?initialReconnectDelay=100&randomize=false&wireFormat.maxInactivityDuration=0
How to correctly initialize ConnectorFactory for it? Should I just do the follwing?
String url = "failover:(tcp://amq.vip.ebay.com:61616,tcp://amqstby.vip.ebay.com:61616)?initialReconnectDelay=100&randomize=false&wireFormat.maxInactivityDuration=0";
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
Or the things are more tricky with this kind of provider urls?
That is the correct syntax. Be careful when turning off the inactivity monitor.
Related
Can someone please help me how to fetch the Enqueue Count for a particular queue in Active MQ?
Here is my code:
BrokerService broker = new BrokerService()
String queueName= "queue.Test"
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory('ACTIVEMQ URL')
Connection connection = connectionFactory.createConnection()
connection.start()
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
ActiveMQDestination requestDestination = session.createTopic(queueName)
QueueViewMBean view = (QueueViewMBean)broker.getDestination(requestDestination)
println("Count = "+view.getEnqueueCount())
But this does not seem to be working. How can I fix it?
You appear to be trying to cast ActiveMQ JMS client resources into JMX MBeans which of course would never work. You need to use JMX to access the management capabilities of the broker.
Some examples of using the MBeans can be found in the unit tests of the broker
I want to know the number of queues on my ActiveMQ and I have this Code, which works with my local installation of ActiveMQ:
ActiveMQSslConnectionFactory connectionFactory = new ActiveMQSslConnectionFactory(url);
//connectionFactory.setTrustStore("truststore.ts");
//connectionFactory.setTrustStorePassword("password");
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
connection.start();
DestinationSource destinationQueues = connection.getDestinationSource();
Set<ActiveMQQueue> queues = destinationQueues.getQueues();
System.out.println(queues.size());
But when I'm using it on our ActiveMQ on the server (with the truststore) it will return zero queues. I know that the connection works because I can consume messages from one exact queue. I already tried tips from other threads like sleep but it still won't work.
Is it maybe because of the SSL Connection, do I have to change something in this case? Thank you in advance.
Found the problem. It's a setting of the ActiveMQ which is found in the activemq.xml. The part advisorySupport="false" caused the problem. After commenting this setting out, the query returns the true amount of queues.
The Destination Source bits make no guarantee of timely return of the full set of Queues etc. It could be you have configured the SSL connector on the broker differently or it could just be that due to the much slower throughput of SSL on JDK implementations the data hasn't arrived.
I already posted a question on this topic some two days earlier, but it was much more complicated question. Now, to put it more simply:
Is there a way to obtain username, used to connect the broker, in spring JMS listener? I have found only MessageListener and SessionAwareMessageListener, but I'm not able to obtain this information (or Connection instnace) from neither Session, nor Message instance.
Am I missing something obvious?
I'm using ActiveMQ embedded broker.
OK, the obvious answer was, that the connection listener is on is not the same connection as the client is on... Therefore, there is NO POINT of obtaining the connection handle...
Stupid me...
PS: I'm leaving it here to warn the future generations.
How about?
#JmsListener(destination = "mytopic")
public void processMessage(BytesMessage message) {
ActiveMQBytesMessage msg = (ActiveMQBytesMessage) message;
ActiveMQConnection conn = msg.getConnection();
ConnectionInfo info = conn.getConnectionInfo();
String username = info.getUserName();
}
In my spring, hibernate application RMQ is used. I have a url in this application to check the status the DB connection and the status of the threads. I also want to include the status check of RMQ connection from the application. Please guide me.
It is hard to give a specific answer as this depends on how you manage connections to the RabbitMQ broker in your application...
However in essence all you need to do is look at the IsOpen property on the connection
You probably have this code somewhere in your application:
ConnectionFactory factory = new ConnectionFactory();
factory.set...
Connection connection = factory.newConnection();
all you need to do to check the current state is:
bool connected = connection.IsOpen();
My question is pretty simple, but I am having a bad time finding a solution.
I want to be able to get all the queues in the server (or session, that would also be ok). Is that possible?
My situation is the following:
I am new to openMQ, Glassfish, activeMQ and so on. I developed a monitoring system for activeMQ in which I get all the existing queues and show to the user, so it can get information about number of messages and so on.
To do that, I have this code:
ActiveMQConnection.makeConnection("tcp://localhost:61616");
activeMQConnection.start();
//Get queues
DestinationSource destinationSource = activeMQConnection.getDestinationSource();
Set<ActiveMQQueue> queues = destinationSource.getQueues();
this last line gets all the queues for the connection, and this is exactly what I need. But this was my code for ActiveMQ.
Now the team decided to change to openMQ, and I have to adapt my monitoring system to be able to handle that. I would like to use LDAP so I can do it technology-independent. After a lot of research I came to this code:
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("cn=QueueConnectionFactory");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue myQueue = session.createQueue("myQueue");
This is good, because it would be completely independente (I think, have to test it). But the problem is that I have to register the queue, something I would not like to do. I would like to get all the existing queues in the server without any need for registering, but I can't find any GetQueues() method or any way to mimic its behavior.
I also found out the the DestinationSource class in activeMQ inherits from MessageListener, but this class doesn't provides any similar method :(
Could you please help me?
thank you,
Oscar
I was able to do that using JMX, here is the code:
HashMap environment = new HashMap();
String[] credentials = new String[] { "user", "pass" };
environment.put(JMXConnector.CREDENTIALS, credentials);
JMXServiceURL url = new JMXServiceURL("URL");
// Get JMX connector, supplying user name and password
JMXConnector jmxc1 = JMXConnectorFactory.connect(url, environment);
// Get MBean server connection
MBeanServerConnection mbsc = jmxc1.getMBeanServerConnection();
ObjectName destMgrConfigName = new ObjectName(MQObjectName.DESTINATION_MANAGER_MONITOR_MBEAN_NAME);
// Create operation's parameter and signature arrays
Object opParams[] = {};
String opSig[] = {};
// Invoke operation
ObjectName[] objectNames = (ObjectName[]) mbsc.invoke(destMgrConfigName, DestinationOperations.GET_DESTINATIONS, opParams, opSig);
for (ObjectName objectName : objectNames) {
System.out.println(objectName.getCanonicalName());
System.out.println(objectName.getKeyProperty("name"));
}
more references here: http://forums.oracle.com/forums/thread.jspa?threadID=2129291&tstart=0