Reputation: 76
I developed a Java EE application (on GlassFish) with an embedded activeMQ message server. I can send messages to my Message Driven Bean. Now I'd like to send message back to another topic over my activeMQ broker.
No message is delivered to the topic "answer". I see it on the activeMQ-web-frontend and no exception is thrown.
I don't see the problem. Can somebody give me a tip where I can search?
Here my classes:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "amqmsg"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic") }, mappedName = "amqmsg")
@TransactionManagement(TransactionManagementType.BEAN)
public class TopicMB implements MessageListener {
@Inject
private MessageSender messageSender;
private static final Logger logger = LoggerFactory.getLogger(TopicMB.class);
public void onMessage(Message message) {
messageLogger.log(message);
try {
messageSender.send("antwort");
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
}
}
}
And my MessageSender. amqpool injects the connector connection pool for acitveMQ.
@Stateless
public class MessageSender {
private static final Logger logger = LoggerFactory
.getLogger(MessageSender.class);
@Resource(name = "amqpool")
private ConnectionFactory connectionFactory;
private static String subject = "answer";
public void send(String text) throws JMSException {
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createTopic(subject);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryDelay(DeliveryMode.PERSISTENT);
TextMessage message = session.createTextMessage("antwort");
// Here we are sending the message!
producer.send(message);
session.close();
}
}
Upvotes: 3
Views: 624
Reputation: 5165
If the message is seen on the webconsole, then it sounds like there is no consumer on the Topic.
Note that Topics never store messages - subscriptions to Topics store messages. Non-durable subscriptions (the default) are only active while the consumer is connected and actively subscribed to the Topic. Durable subscriptions can hold messages while the consumer is not connected.
So, is there a consumer on the Topic at the time the message is sent to it, or a registered durable subscription on the Topic?
Upvotes: 0