本文整理匯總了Java中javax.jms.Session.commit方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.commit方法的具體用法?Java Session.commit怎麽用?Java Session.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.Session
的用法示例。
在下文中一共展示了Session.commit方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: putTopic
import javax.jms.Session; //導入方法依賴的package包/類
private void putTopic(List<String> events) throws Exception {
ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
PASSWORD, BROKER_BIND_URL);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createTopic(DESTINATION_NAME);
MessageProducer producer = session.createProducer(destination);
for (String event : events) {
TextMessage message = session.createTextMessage();
message.setText(event);
producer.send(message);
}
session.commit();
session.close();
connection.close();
}
示例2: putQueue
import javax.jms.Session; //導入方法依賴的package包/類
private void putQueue(List<String> events) throws Exception {
ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
PASSWORD, BROKER_BIND_URL);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(DESTINATION_NAME);
MessageProducer producer = session.createProducer(destination);
for (String event : events) {
TextMessage message = session.createTextMessage();
message.setText(event);
producer.send(message);
}
session.commit();
session.close();
connection.close();
}
示例3: doPublish
import javax.jms.Session; //導入方法依賴的package包/類
protected void doPublish(Event event) throws EdsException {
Connection conn = null;
Session session = null;
MessageProducer messageProducer = null;
try {
LOG.debug("eds pub 3 mq in -[event:" + event + "]");
conn = connectionFactory.createConnection();
// 設置非事務,客戶端確認方式
session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MapMessage mapMessage = session.createMapMessage();
mapMessage = EventConverter.convertToMessage(mapMessage, event);
Destination dest = getDestination(event.getName(), session);
messageProducer = session.createProducer(dest);
messageProducer.send(mapMessage);
// commit session if necessary
if (session.getTransacted()) {
session.commit();
}
LOG.debug("eds pub 4 mq ok -[conn:" + conn + ",session:" + session + ",event:" + event + "]");
}catch(JMSException e){
throw new EdsException("eds client activemq doPublish exception ", e);
}finally {
releaseSession(session);
releaseMessageProducer(messageProducer);
releaseConnection(conn, false);
}
}
示例4: queueMessage
import javax.jms.Session; //導入方法依賴的package包/類
static void queueMessage(Session session, String text, String queueName) {
try {
Queue queue = session.createQueue(queueName);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage(text);
message.setJMSCorrelationID(MDC.get(X_OBOS_REQUEST_ID));
producer.send(message);
session.commit();
} catch (JMSException ex) {
throw new MessageQueueException("Could not queue message '" + text + "'", ex);
}
}
示例5: requeueFailedMessages
import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void requeueFailedMessages() {
try {
ActiveMQConnection connection = ActiveMqUtils.openConnection(user, password, url);
Session session = ActiveMqUtils.startSession(connection);
int count = getQueueSize(session, queueError);
if (count < 1) {
return;
}
log.info("Requeuing {} failed messages...", count);
Queue queueErr = session.createQueue(queueError);
MessageConsumer consumer = session.createConsumer(queueErr);
Queue queueRetry = session.createQueue(queueInput);
MessageProducer producer = session.createProducer(queueRetry);
for (int consumed = 0; consumed < count; consumed++) {
TextMessage message = (TextMessage) consumer.receive(REQUEUE_TIMEOUT);
if (message == null) {
continue;
}
String text = message.getText();
String requestId = message.getJMSCorrelationID();
log.info("Requeuing message '{}'", text);
try {
TextMessage newMessage = session.createTextMessage(text);
newMessage.setJMSCorrelationID(requestId);
producer.send(newMessage);
} catch (Exception e) {
log.error("Failed to requeue message", e);
}
message.acknowledge();
session.commit();
}
producer.close();
consumer.close();
} catch (JMSException ex) {
throw new MessageQueueException("Failed to requeue failed messages", ex);
}
}