use of javax.jms.Topic in project ignite by apache.
the class JmsStreamer method start.
/**
* Starts streamer.
*
* @throws IgniteException If failed.
*/
public void start() throws IgniteException {
if (!stopped)
throw new IgniteException("Attempted to start an already started JMS Streamer");
try {
A.notNull(getStreamer(), "streamer");
A.notNull(getIgnite(), "ignite");
log = getIgnite().log();
A.notNull(transformer, "message transformer");
A.notNull(connectionFactory, "connection factory");
A.ensure(threads > 0, "threads > 0");
// handle batched && transacted parameter interaction
if (batched && !transacted) {
log.warning("Starting a Batched JMS Streamer without transacted flag = true. Setting it automatically.");
transacted = true;
}
// handle batch completion criteria
if (batched) {
A.ensure(batchClosureMillis > 0 || batchClosureSize > 0, "at least one of batch closure size or " + "batch closure frequency must be specified when using batch consumption");
}
// check the parameters needed for durable subscriptions, if enabled
if (durableSubscription) {
A.notNullOrEmpty(clientId, "client id is compulsory when using durable subscriptions");
A.notNullOrEmpty(durableSubscriptionName, "durable subscription name is compulsory when using " + "durable subscriptions");
}
// else make sure that the destinationName and the destinationType are valid
if (destination == null) {
A.notNull(destinationType, "destination type");
A.ensure(destinationType.isAssignableFrom(Queue.class) || destinationType.isAssignableFrom(Topic.class), "this streamer can only handle Queues or Topics.");
A.notNullOrEmpty(destinationName, "destination or destination name");
} else if (destination instanceof Queue) {
destinationType = Queue.class;
} else if (destination instanceof Topic) {
destinationType = Topic.class;
} else {
throw new IllegalArgumentException("Invalid destination object. Can only handle Queues or Topics.");
}
// create a new connection and the client iD if relevant.
connection = connectionFactory.createConnection();
if (clientId != null && clientId.trim().length() > 0) {
connection.setClientID(clientId.trim());
}
// build the JMS objects
if (destinationType == Queue.class) {
initializeJmsObjectsForQueue();
} else {
initializeJmsObjectsForTopic();
}
stopped = false;
// start the JMS connection
connection.start();
// set up the scheduler service for committing batches
if (batched && batchClosureMillis > 0) {
scheduler = Executors.newScheduledThreadPool(1);
scheduler.schedule(new Runnable() {
@Override
public void run() {
for (Session session : sessions) {
try {
session.commit();
if (log.isDebugEnabled()) {
log.debug("Committing session from time-based batch completion [session=" + session + "]");
}
} catch (JMSException ignored) {
log.warning("Error while committing session: from batch time-based completion " + "[session=" + session + "]");
}
}
for (IgniteJmsMessageListener ml : listeners) {
ml.resetBatchCounter();
}
}
}, batchClosureMillis, TimeUnit.MILLISECONDS);
}
} catch (Throwable t) {
throw new IgniteException("Exception while initializing JmsStreamer", t);
}
}
use of javax.jms.Topic in project tech by ffyyhh995511.
the class TopicReceive method init.
public void init() throws Exception {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://127.0.0.1:61616");
Connection connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("fyhTopic");
consumer = session.createConsumer(topic);
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
TextMessage tm = (TextMessage) message;
System.out.println(tm);
try {
System.out.println(tm.getText());
} catch (JMSException e) {
e.printStackTrace();
}
}
});
}
use of javax.jms.Topic in project tech by ffyyhh995511.
the class TopicRequest method init.
public void init() throws Exception {
// ConnectionFactory连接工厂,JMS用它创建连接
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://127.0.0.1:61616");
// 从构造工厂中得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取连接操作
session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("fyhTopic");
producer = session.createProducer(topic);
// 设置不持久化
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
use of javax.jms.Topic in project cxf by apache.
the class JmsPublisher method notify.
@Override
public void notify(NotificationMessageHolderType messageHolder) {
Session session = null;
try {
Topic topic = topicConverter.toActiveMQTopic(messageHolder.getTopic());
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
Notify notify = new Notify();
notify.getNotificationMessage().add(messageHolder);
StringWriter writer = new StringWriter();
jaxbContext.createMarshaller().marshal(notify, writer);
Message message = session.createTextMessage(writer.toString());
producer.send(message);
} catch (JMSException e) {
LOGGER.log(Level.WARNING, "Error dispatching message", e);
} catch (JAXBException e) {
LOGGER.log(Level.WARNING, "Error dispatching message", e);
} catch (InvalidTopicException e) {
LOGGER.log(Level.WARNING, "Error dispatching message", e);
} finally {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
LOGGER.log(Level.FINE, "Error closing session", e);
}
}
}
}
Aggregations