A simple message publisher looks like:
@Service("myPublisher")
public class MyPublisher{
@Publisher(channel = "myChannel")
public Message<?> sendMessage (Message<?> message) {
return message;
}
}
...and is configures like this:
<int:channel id="myChannel"/>
<int-jms:outbound-channel-adapter channel="myChannel" destination="defaultDestination" session-transacted="true"/>
<bean class="org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor"/>
The Problem is, this publisher sends messages to a prepared defaultDestination
, but I need to send messages to different queues. In my case I need a message queue for every task in my application. The reason is, if I want to abort a task, I must remove the messages from the broker. If there are thousands of messages for one task, it is not a good practice to receive all messages with a selector. I need to to remove all messages of the aborted task from the message broker without receiving of a client. JMS only supports sending and receiving of messages. I must use the broker API (QPID) to remove the messages. The problem is, QPID doesn't support removing of messages by a selector, but it supports removing of queues.
I think, I need a PublisherFactory, with a function like this:
public class PublisherFactory {
public MyPublisher getPublisher(String destinationName){...};
}
factory.getPublisher("testQueue");
This method should return a publisher that sends messages to the testQueue
.
Or a service with a function like this:
public class PublisherService {
public Message<?> sendMessage(Message<?> message, String desinationName){...};
}
service.sendMessage(new Message("test"), "testQueue");
In short words, all I want, is a service that sends a Message
to a specific destination. The destination name should be set either as a param over method call or as a class variable over a factory.
I hope, someone has the solution of my problem. Thanks :)