use of javax.jms.TopicPublisher in project activemq-artemis by apache.
the class AcknowledgementTest method testPersistentMessagesForTopicDropped.
/**
* Topics shouldn't hold on to messages if there are no subscribers
*/
@Test
public void testPersistentMessagesForTopicDropped() throws Exception {
TopicConnection topicConn = createTopicConnection();
TopicSession sess = topicConn.createTopicSession(true, 0);
TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
pub.setDeliveryMode(DeliveryMode.PERSISTENT);
Message m = sess.createTextMessage("testing123");
pub.publish(m);
sess.commit();
topicConn.close();
checkEmpty(ActiveMQServerTestCase.topic1);
}
use of javax.jms.TopicPublisher in project activemq-artemis by apache.
the class SimpleOpenWireTest method testTempTopicDelete.
@Test
public void testTempTopicDelete() throws Exception {
connection.start();
TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryTopic tempTopic = topicSession.createTemporaryTopic();
ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
try {
TopicSession newTopicSession = newConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher publisher = newTopicSession.createPublisher(tempTopic);
TextMessage msg = newTopicSession.createTextMessage("Test Message");
publisher.publish(msg);
try {
TopicSubscriber consumer = newTopicSession.createSubscriber(tempTopic);
fail("should have gotten exception but got consumer: " + consumer);
} catch (JMSException ex) {
// correct
}
connection.close();
try {
Message newMsg = newTopicSession.createMessage();
publisher.publish(newMsg);
} catch (JMSException e) {
// ok
}
} finally {
newConn.close();
}
}
use of javax.jms.TopicPublisher in project moleculer-java by moleculer-java.
the class JmsTransporter method publish.
// --- PUBLISH ---
@Override
public void publish(String channel, Tree message) {
if (client != null) {
try {
if (debug) {
logger.info("Submitting message to channel \"" + channel + "\":\r\n" + message.toString());
}
TopicPublisher publisher = createOrGetPublisher(channel);
BytesMessage msg = session.createBytesMessage();
msg.writeBytes(serializer.write(message));
if (transacted) {
synchronized (this) {
try {
publisher.send(msg, deliveryMode, priority, ttl);
session.commit();
} catch (Exception cause) {
try {
session.rollback();
} catch (Exception ignored) {
}
throw cause;
}
}
} else {
publisher.send(msg, deliveryMode, priority, ttl);
}
} catch (Exception cause) {
logger.warn("Unable to send message to JMS server!", cause);
}
}
}
use of javax.jms.TopicPublisher in project ofbiz-framework by apache.
the class JmsServiceEngine method runTopic.
protected Map<String, Object> runTopic(ModelService modelService, Map<String, Object> context, Server server) throws GenericServiceException {
String serverName = server.getJndiServerName();
String jndiName = server.getJndiName();
String topicName = server.getTopicQueue();
String userName = server.getUsername();
String password = server.getPassword();
String clientId = server.getClientId();
InitialContext jndi = null;
TopicConnectionFactory factory = null;
TopicConnection con = null;
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (TopicConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge.getNested());
} catch (NamingException ne) {
JNDIContextFactory.clearInitialContext(serverName);
try {
jndi = JNDIContextFactory.getInitialContext(serverName);
factory = (TopicConnectionFactory) jndi.lookup(jndiName);
} catch (GeneralException ge2) {
throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested());
} catch (NamingException ne2) {
throw new GenericServiceException("JNDI lookup problems.", ne);
}
}
try {
con = factory.createTopicConnection(userName, password);
if (clientId != null && clientId.length() > 1)
con.setClientID(clientId);
con.start();
TopicSession session = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) jndi.lookup(topicName);
TopicPublisher publisher = session.createPublisher(topic);
// create/send the message
Message message = makeMessage(session, modelService, context);
publisher.publish(message);
if (Debug.verboseOn())
Debug.logVerbose("Sent JMS Message to " + topicName, module);
// close the connections
publisher.close();
session.close();
con.close();
} catch (NamingException ne) {
throw new GenericServiceException("Problems with JNDI lookup.", ne);
} catch (JMSException je) {
throw new GenericServiceException("JMS Internal Error.", je);
}
return ServiceUtil.returnSuccess();
}
use of javax.jms.TopicPublisher in project iaf by ibissource.
the class JMSFacade method sendByTopic.
protected String sendByTopic(TopicSession session, Topic destination, javax.jms.Message message) throws NamingException, JMSException {
TopicPublisher tps = session.createPublisher(destination);
tps.publish(message);
tps.close();
return message.getJMSMessageID();
}
Aggregations