Topic and queue with the same name, classcastexception - apache

my question is, using ActiveMQ can we have a topic and queue with the same name for jndi?.
I have both defined with the same name, and when I try to create a queue with lookup I´m receiving this exception.
java.lang.ClassCastException: org.apache.activemq.command.ActiveMQTopic cannot be cast to javax.jms.Queue

While you can actually have a topic and queue with the same name you cannot share a JNDI name between a topic and a queue. A JNDI name makes you lookup a single object (queue or topic).
So - make sure you have JNDI entries with unique names.
queue.MyQueue = samePhysicalName
topic.MyTopic = samePhysicalName
Although I think it's bad practice to share names, since it's harder to document, trouble shoot etc etc.

Related

How to handle Not authorized to access topic ... in Kafka Streams

Situation is the following.
We have setup SSL + ACLs in Kafka Broker.
We are setting up stream, which reads messages from two topics:
KStream<String, String> stringInput
= kBuilder.stream( STRING_SERDE, STRING_SERDE, inTopicName );
stringInput
.filter( streamFilter::passOrFilterMessages )
.map( processor )
.to( outTopicName );
It is done like two times (in the loop).
Then we are setting general error handler:
streams.setUncaughtExceptionHandler( ( Thread t, Throwable e ) -> {
synchronized ( this ) {
LOG.fatal( ... );
this.stop();
}
}
);
Problem is the following. If for example in one topic certificate is no more valid. The stream is throwing exception Not authorized to access topics ...
So far so good.
But the exception is handled by general error handler, so the complete application stops even if the second topic has no problems.
The question is, how to handle this exception per topic?
How to avoid situation that at some moment complete application stops due to the problem that one single topic has problems with authorization?
I understand that if Broker is not available, then complete app may stop. But if only one topic is not available, then single stream shall stop, and not complete application, or?
By design, Kafka Streams treats the topology a one and cannot distinguish between both parts. For your specific case, as you loop and build to independent pipelines, you could run two KafkaStreams instances in parallel (within the same application/JVM) to isolate both from each other. Thus, if one fails, the other one is not affected. You would need to use two different application.id for both instances.

Is it possbile to have multiple instances of the service with the same clientId in ActiveMQ?

I've created a test with two consumers each using its own connection. I need to be sure that only one of them receives the message.
These consumers use the same clientId and name.
Whenever I set clientId for the second consumer I get the following exception:
Apache.NMS.InvalidClientIDException: Broker: localhost - Client: TwoDurableConsumers_SameConsumerNameAndCientId_OnlyOneReceivesMessageb9182d05-b1b4-46b0-afb0-074b52ad7071 already connected from tcp://0:0:0:0:0:0:0:1:58629
at Apache.NMS.ActiveMQ.Connection.CheckConnected() in c:\dev\NMS.ActiveMQ\src\main\csharp\Connection.cs:line 1041
TwoDurableConsumers_SameConsumerNameAndCientId_OnlyOneReceivesMessageb9182d05-b1b4-46b0-afb0-074b52ad7071 is both clientId and durable subscriber name.
You cannot have two clients with the same client ID which is what the error is telling you. The client ID is a unique identifier which works to prevent exactly what you are trying to do, so the answer is don't do that.

ActiveMQ Durable Subscriber with jmsMessageId

I'm new to ActiveMQ and trying to find anything that explicitly outlines how JMSMessageID behaves with durable subscribers and selectors, however, I am struggling to find much.
As an example: JMSType = 'car' AND color = 'blue' AND weight > 2500 as a selector. Each subscriber will only receive messages from the topic where the criteria match. When each receives said messages are the JSMMessageID unique for each subscriber or are they unique for the entire topic before it was filtered by the selector for the subscriber.
If not is there a way that I can get the JSMessageID to be unique for each subscriber so that it can be used as a form of sequence number using custom messageID layout: 1, 2, 3... ad infinitum.
The Message ID is set by the producer at the time of send, the broker passes along a copy of the message to each Topic subscription (durable or not) with the message ID that it was sent with. You cannot alter the ID the broker uses that value to track the message and ensure that it is preserved until each subscription that it was dispatched to or stored for has acknowledged it.

Calling gracefulStop Singleton Actor

For testing purposes, I'm trying to restart a singleton actor (created using ClusterSingletonManager and ClusterSingletonProxy). However, the documentation for gracefulStop says:
IMPORTANT NOTICE: the actor being terminated and its supervisor being informed of the availability of the deceased actor’s name are two distinct operations, which do not obey any reliable ordering. Especially the following will NOT work:
def receive = {
case msg =>
Await.result(gracefulStop(someChild, timeout), timeout)
context.actorOf(Props(...), "someChild") // assuming that that was someChild’s name, this will NOT work
}
Does anyone know a way around this? Please don't tell me to use Thread.sleep. A blocking loop that checks for the name availability would be OK, though a less hack-ish way would be preferable. If that's the only way, how can one check if an actor name is available?

get queuename on activemq server to push message

I have got 10 queues on activemq server.
I have producer which want to push messages on one of the queue (the producer will select the queue randomly run time to put message on queue), how can I pass destination name in createProducer method.
I understand that I need to pass an object of type Destination. the producer would know the queues name on the server. Is it possible to pass (or convert) a string to Destination object type and pass that to createproducer method.
Thanks
If I understand your problem correctly;
If you're running Java and have a valid session, you could use Session.createQueue();
// Create a Destination using the queue name
Destination destination = session.createQueue("queue name");
// Create a MessageProducer from the Session to the Queue
MessageProducer producer = session.createProducer(destination);
Here is a complete example of doing this at the Apache site.