Send message on embedded activeMQ messaging server to glass fish
I have developed a Java EE application (on GlassFish) with a built-in activeMQ messaging server. I can post messages to my Driven Bean message. Now I would like to post back to a different topic via my activeMQ broker.
No message is sent to the "Reply" section. I can see this in the activeMQ web interface and no exception is thrown.
I don't see the problem. Can someone give me a hint where I can look?
Here's 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 introduces connector connection pooling 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();
}
}
source to share
If the message is displayed on the web console, it sounds like there is no consumer in the topic.
Please note that themes never save posts - subscriptions to theme store posts. Continuous subscriptions (default) are active only when a consumer is connected and actively subscribes to a topic. Long term subscriptions can contain messages while the consumer is not connected.
So, is there a consumer on the topic at the time of posting, or is there a registered long-term subscription to the topic?
source to share