當前位置: 首頁>>代碼示例>>Java>>正文


Java Session.SESSION_TRANSACTED屬性代碼示例

本文整理匯總了Java中javax.jms.Session.SESSION_TRANSACTED屬性的典型用法代碼示例。如果您正苦於以下問題:Java Session.SESSION_TRANSACTED屬性的具體用法?Java Session.SESSION_TRANSACTED怎麽用?Java Session.SESSION_TRANSACTED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.jms.Session的用法示例。


在下文中一共展示了Session.SESSION_TRANSACTED屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

/**
 * Sends the given {@code events} to the configured JMS Topic. It takes the current Unit of Work
 * into account when available. Otherwise, it simply publishes directly.
 *
 * @param events the events to publish on the JMS Message Broker
 */
protected void send(List<? extends EventMessage<?>> events) {
  try (TopicConnection topicConnection = connectionFactory.createTopicConnection()) {
    int ackMode = isTransacted ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE;
    TopicSession topicSession = topicConnection.createTopicSession(isTransacted, ackMode);
    try (TopicPublisher publisher = topicSession.createPublisher(topic)) {
      for (EventMessage event : events) {
        Message jmsMessage = messageConverter.createJmsMessage(event, topicSession);
        doSendMessage(publisher, jmsMessage);
      }
    } finally {
      handleTransaction(topicSession);
    }
  } catch (JMSException ex) {
    throw new EventPublicationFailedException(
        "Unable to establish TopicConnection to JMS message broker.", ex);
  }
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:23,代碼來源:JmsPublisher.java

示例2: getSessionAcknowledgeMode

protected int getSessionAcknowledgeMode(boolean transacted, int acknowledgeMode) throws JMSException {
    int result = acknowledgeMode;
    if (!transacted && acknowledgeMode == Session.SESSION_TRANSACTED) {
        throw new JMSException("acknowledgeMode SESSION_TRANSACTED cannot be used for an non-transacted Session");
    }

    if (transacted) {
        result = Session.SESSION_TRANSACTED;
    } else if (acknowledgeMode < Session.SESSION_TRANSACTED || acknowledgeMode > Session.DUPS_OK_ACKNOWLEDGE){
        throw new JMSException("acknowledgeMode " + acknowledgeMode + " cannot be used for an non-transacted Session");
    }

    return result;
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:14,代碼來源:MockJMSConnection.java

示例3: doTestCreateSessionWithGivenAckModeAndTXFlag

public void doTestCreateSessionWithGivenAckModeAndTXFlag(boolean transacted, int ackMode) throws Exception {
    Connection connection = cf.createConnection();

    if (!transacted && ackMode == Session.SESSION_TRANSACTED) {
        try {
            connection.createSession(transacted, ackMode);
            fail("Should not allow non-transacted session with SESSION_TRANSACTED");
        } catch (JMSException jmsex) {}
    } else {
        Session session1 = connection.createSession(transacted, ackMode);
        Session session2 = connection.createSession(transacted, ackMode);

        assertNotSame(session1, session2);

        if (transacted) {
            assertEquals(session1.getAcknowledgeMode(), Session.SESSION_TRANSACTED);
            assertEquals(session2.getAcknowledgeMode(), Session.SESSION_TRANSACTED);
        } else {
            assertEquals(session1.getAcknowledgeMode(), ackMode);
            assertEquals(session2.getAcknowledgeMode(), ackMode);
        }

        JmsPoolSession wrapperSession1 = (JmsPoolSession) session1;
        JmsPoolSession wrapperSession2 = (JmsPoolSession) session2;

        assertNotSame(wrapperSession1.getSession(), wrapperSession2.getSession());
    }
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:28,代碼來源:JmsPoolConnectionTest.java

示例4: processMessage

private void processMessage(Message message) throws Throwable {
	if (null == message) {
		// log.error("message is null...");
		return;
	}
	try {
		XCO xcoMessage = null;
		if (message instanceof TextMessage) {
			TextMessage textMessage = (TextMessage) message;
			String text = textMessage.getText();
			xcoMessage = XCO.fromXML(text);
		} else {
			// TODO
		}

		log.info("received a message from " + typeStr + "[" + queue.getName() + "]: " + xcoMessage);

		boolean execResult = true;
		if (null != xcoMessage) {
			execResult = exec(service, xcoMessage, binding);
		}

		if (execResult && Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) {
			session.commit();
		} else if (execResult && Session.CLIENT_ACKNOWLEDGE == session.getAcknowledgeMode()) {
			message.acknowledge();
		}

		if (!execResult && Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) {
			session.rollback();
		}
	} catch (Throwable e) {
		if (Session.SESSION_TRANSACTED == session.getAcknowledgeMode()) {
			session.rollback();
		}
		throw e;
	}
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:38,代碼來源:ActiveMqReceiver.java

示例5: getSession

/**
 *
 * @param ackMode
 *            The acknowledgement mode
 * @return A {@link Session} on the provided Connection
 * @throws JMSException
 *             An instance of {@link JMSException}
 */
public static Session getSession(int ackMode) throws JMSException {
	Session session = null;
	if (CONNECTION_ATOMIC_REFERENCE.get() != null) {
		boolean transacted = (ackMode == Session.SESSION_TRANSACTED ? true : false);
		session = CONNECTION_ATOMIC_REFERENCE.get().createSession(transacted, ackMode);
	} else {
		logger.debug("A connection instance needs to be created first before trying to create session!");
	}
	return session;
}
 
開發者ID:chakrs,項目名稱:amqp,代碼行數:18,代碼來源:SimpleConnectionProvider.java

示例6: sendQueueMessage

private void sendQueueMessage(ActiveMqChannelVo queue, Object arg, boolean useTx, MqServiceContext context) throws Throwable {
	ActiveMqSource mqSource = (ActiveMqSource) MqContainer.getInstance().getMqSourceManager().getMqSource(queue.getMsKey());
	Connection connection = null;
	Session session = null;
	Throwable tx = null;

	boolean transacted = false;
	int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
	if (useTx) {
		transacted = true;
		acknowledgeMode = Session.SESSION_TRANSACTED;
	}

	try {
		session = mqSource.getSession(transacted, acknowledgeMode);
		if (null == session) {
			connection = mqSource.getConnection();
			session = connection.createSession(transacted, acknowledgeMode);
		}

		if (useTx) {
			context.addTransactionObject(new ActiveMqTransactionObject(mqSource, session));
		}

		Destination destination = session.createQueue(queue.getName());
		MessageProducer messageProducer = session.createProducer(destination);
		TextMessage message = session.createTextMessage(((XCO) arg).toXMLString());

		// int deliveryMode = (Integer) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_P_DELIVERYMODE);
		// long timeToLive = (Long) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_P_TIMETOLIVE);

		int deliveryMode = queue.getDeliveryMode();
		long timeToLive = queue.getTimeToLive();

		messageProducer.send(message, deliveryMode, Message.DEFAULT_PRIORITY, timeToLive);

		// log.info("send queue: " + ((XCO) arg).toXMLString());
		log.info("send message to queue[" + queue.getName() + "]: " + ((XCO) arg).toXMLString());

	} catch (Throwable e) {
		tx = e;
	} finally {
		if (null != session && !useTx) {
			mqSource.closeSession(session, transacted);
		}
		if (null != tx) {
			throw tx;
		}
	}
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:50,代碼來源:ActiveMqSender.java

示例7: sendTopicMessage

private void sendTopicMessage(ActiveMqChannelVo queue, Object arg, boolean useTx, MqServiceContext context) throws Throwable {
	ActiveMqSource mqSource = (ActiveMqSource) MqContainer.getInstance().getMqSourceManager().getMqSource(queue.getMsKey());
	Connection connection = null;
	Session session = null;
	Throwable tx = null;

	boolean transacted = false;
	int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
	if (useTx) {
		transacted = true;
		acknowledgeMode = Session.SESSION_TRANSACTED;
	}

	try {

		session = mqSource.getSession(transacted, acknowledgeMode);
		if (null == session) {
			connection = mqSource.getConnection();
			session = connection.createSession(transacted, acknowledgeMode);
		}

		if (useTx) {
			context.addTransactionObject(new ActiveMqTransactionObject(mqSource, session));
		}

		Destination destination = session.createTopic(queue.getName());
		MessageProducer messageProducer = session.createProducer(destination);
		TextMessage message = session.createTextMessage(((XCO) arg).toXMLString());

		// int deliveryMode = (Integer) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_P_DELIVERYMODE);
		// long timeToLive = (Long) queue.getProperties().get(ActiveMqVo.ACTIVEMQ_P_TIMETOLIVE);

		int deliveryMode = queue.getDeliveryMode();
		long timeToLive = queue.getTimeToLive();

		messageProducer.send(message, deliveryMode, Message.DEFAULT_PRIORITY, timeToLive);

		log.info("send message to topic[" + queue.getName() + "]: " + ((XCO) arg).toXMLString());

	} catch (Throwable e) {
		tx = e;
	} finally {
		if (null != session && !useTx) {
			mqSource.closeSession(session, transacted);
		}
		if (null != tx) {
			throw tx;
		}
	}
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:50,代碼來源:ActiveMqSender.java


注:本文中的javax.jms.Session.SESSION_TRANSACTED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。