本文整理匯總了Java中javax.jms.Session.createTextMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.createTextMessage方法的具體用法?Java Session.createTextMessage怎麽用?Java Session.createTextMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.Session
的用法示例。
在下文中一共展示了Session.createTextMessage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: receiveAndRespondWithMessageIdAsCorrelationId
import javax.jms.Session; //導入方法依賴的package包/類
public void receiveAndRespondWithMessageIdAsCorrelationId(ConnectionFactory connectionFactory, String queueName) throws JMSException {
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
final javax.jms.Message inMessage = consumer.receive();
String requestMessageId = inMessage.getJMSMessageID();
LOG.debug("Received message " + requestMessageId);
final TextMessage replyMessage = session.createTextMessage("Result");
replyMessage.setJMSCorrelationID(inMessage.getJMSMessageID());
final MessageProducer producer = session.createProducer(inMessage.getJMSReplyTo());
LOG.debug("Sending reply to " + inMessage.getJMSReplyTo());
producer.send(replyMessage);
producer.close();
consumer.close();
session.close();
connection.close();
}
示例3: sendWithReplyToTemp
import javax.jms.Session; //導入方法依賴的package包/類
private void sendWithReplyToTemp(ConnectionFactory cf, String serviceQueue) throws JMSException, InterruptedException {
Connection connection = cf.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Request");
msg.setJMSReplyTo(tempQueue);
MessageProducer producer = session.createProducer(session.createQueue(serviceQueue));
producer.send(msg);
MessageConsumer consumer = session.createConsumer(tempQueue);
Message replyMsg = consumer.receive();
assertNotNull(replyMsg);
LOG.debug("Reply message: {}", replyMsg);
consumer.close();
producer.close();
session.close();
connection.close();
}
示例4: publiceerMaakSelectieGeenResultaatNetwerkTaak
import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerMaakSelectieGeenResultaatNetwerkTaak(List<MaakSelectieResultaatTaak> maakSelectieGeenResultaatNetwerkTaken) {
LOGGER.info("publiceer maak selectie resultaat taken");
final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
LOGGER.debug("publiceer maak selectie resultaat taak");
for (final MaakSelectieResultaatTaak maakSelectieGeenResultaatNetwerkTaak : maakSelectieGeenResultaatNetwerkTaken) {
final String
groupId =
maakSelectieGeenResultaatNetwerkTaak.getSelectieRunId() + "_" + maakSelectieGeenResultaatNetwerkTaak
.getToegangLeveringsAutorisatieId()
+ "_"
+ maakSelectieGeenResultaatNetwerkTaak.getDienstId();
final Message message = session.createTextMessage(serializer.serialiseerNaarString(maakSelectieGeenResultaatNetwerkTaak));
message.setStringProperty(LeveringConstanten.JMS_MESSAGEGROUP_HEADER, groupId);
producer.send(message);
}
return null;
};
PublicatieHelper.publiceer(maakSelectieGeenResultaatNetwerkTemplate, producerCallback,
() -> "fout in verzenden berichten naar maak selectie geen resultaat netwerk taak queue");
}
示例5: doSendTextMessage
import javax.jms.Session; //導入方法依賴的package包/類
private void doSendTextMessage( final Session session, final Destination destination,
final String textMessage,
final Map<String, ?> properties ) throws JMSException {
try {
final Message message = textMessage != null
? session.createTextMessage(textMessage)
: session.createTextMessage();
if (properties != null) {
// Note: Setting any properties (including JMS fields) using
// setObjectProperty might not be supported by all providers
// Tested with: ActiveMQ
for (final Entry<String, ?> property : properties.entrySet()) {
message.setObjectProperty(property.getKey(), property.getValue());
}
}
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
} finally {
releaseSession(false);
}
}
示例6: validateFactoryCreationWithActiveMQLibraries
import javax.jms.Session; //導入方法依賴的package包/類
/**
* This test simply validates that {@link ConnectionFactory} can be setup by
* pointing to the location of the client libraries at runtime. It uses
* ActiveMQ which is not present at the POM but instead pulled from Maven
* repo using {@link TestUtils#setupActiveMqLibForTesting(boolean)}, which
* implies that for this test to run the computer must be connected to the
* Internet. If computer is not connected to the Internet, this test will
* quietly fail logging a message.
*/
@Test
public void validateFactoryCreationWithActiveMQLibraries() throws Exception {
try {
String libPath = TestUtils.setupActiveMqLibForTesting(true);
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
runner.addControllerService("cfProvider", cfProvider);
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI,
"vm://localhost?broker.persistent=false");
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, libPath);
runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
"org.apache.activemq.ActiveMQConnectionFactory");
runner.enableControllerService(cfProvider);
runner.assertValid(cfProvider);
Connection connection = cfProvider.getConnectionFactory().createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination queue = session.createQueue("myqueue");
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer = session.createConsumer(queue);
TextMessage message = session.createTextMessage("Hello");
producer.send(message);
assertEquals("Hello", ((TextMessage) consumer.receive()).getText());
connection.stop();
connection.close();
} catch (Exception e) {
logger.error("'validateFactoryCreationWithActiveMQLibraries' failed due to ", e);
}
}
示例7: 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();
}
示例8: createMessage
import javax.jms.Session; //導入方法依賴的package包/類
public Message createMessage(Object messageObject) throws JMSException {
Connection connection = null;
Message result = null;
try {
connection = startConnection();
Session session = null;
try {
session = connection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
if (messageObject == null) {
result = session.createMessage();
} else {
if (messageObject instanceof String) {
result = session.createTextMessage((String) messageObject);
} else {
result = session.createObjectMessage((Serializable) messageObject);
}
}
} finally {
if (session != null) session.close();
}
} finally {
safeCloseConnection(connection);
}
return result;
}
示例9: handleMessage
import javax.jms.Session; //導入方法依賴的package包/類
private void handleMessage(MessageHandler handler, Message message, Session session) {
if (! (message instanceof TextMessage)) {
return;
}
TextMessage textMessage = (TextMessage) message;
String text = null;
String requestId = UUID.randomUUID().toString();
try {
text = textMessage.getText();
if (StringUtils.isNotEmpty(message.getJMSCorrelationID())) {
requestId = message.getJMSCorrelationID();
}
MDC.put(X_OBOS_REQUEST_ID, requestId);
log.info("Received message '{}'", text);
handler.handle(new ObjectMapper().readTree(text));
} catch (Exception e) {
log.error("Failed to process message", e);
try {
TextMessage errorMessage = session.createTextMessage(text);
errorMessage.setJMSCorrelationID(requestId);
Queue queue = session.createQueue(queueError);
MessageProducer errorProducer = session.createProducer(queue);
errorProducer.send(errorMessage);
} catch (JMSException jmse) {
log.error("Failed to create error message", jmse);
}
} finally {
MDC.remove(X_OBOS_REQUEST_ID);
}
}
示例10: publiceerSchrijfTaken
import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerSchrijfTaken(List<SelectieFragmentSchrijfBericht> schrijfTaken) {
LOGGER.info("publiceer selectie schrijf taken");
final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
for (final SelectieFragmentSchrijfBericht selectieTaak : schrijfTaken) {
LOGGER.debug("publiceer selectie schrijf taak");
final Message message = session.createTextMessage(serializer.serialiseerNaarString(selectieTaak));
message.setStringProperty(LeveringConstanten.JMS_MESSAGEGROUP_HEADER, String.valueOf(selectieTaak.getSelectietaakId()));
producer.send(message);
}
return null;
};
publiceer(selectieTaakJmsTemplate, producerCallback,
() -> "fout in verzenden berichten naar selectie schrijf taak queue");
}
示例11: publiceerSelectieTaak
import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerSelectieTaak(final List<SelectieVerwerkTaakBericht> selectieTaken) {
final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
for (final SelectieVerwerkTaakBericht selectieTaak : selectieTaken) {
final Message message = session.createTextMessage(serializer.serialiseerNaarString(selectieTaak));
producer.send(message);
}
return null;
};
publiceer(selectieTaakJmsTemplate, producerCallback, () -> "fout in verzenden berichten naar selectie taak queue");
}
示例12: 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);
}
}
示例13: main
import javax.jms.Session; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("HELLOWORLD.TESTQ");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a messages
String text = "Hello world! From: " + Thread.currentThread().getName();
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
producer.send(message);
// Clean up
session.close();
connection.close();
}
catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
示例14: run
import javax.jms.Session; //導入方法依賴的package包/類
public void run() {
try {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("HELLOWORLD.TESTQ");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a messages
String text = "Hello world! From: " + Thread.currentThread().getName() + " : " + this.hashCode();
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
producer.send(message);
// Clean up
session.close();
connection.close();
}
catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
示例15: publiceerSelectieTaakResultaat
import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void publiceerSelectieTaakResultaat(final SelectieTaakResultaat selectieTaakResultaat) {
final ProducerCallback<Void> producerCallback = (final Session session, final MessageProducer producer) -> {
final Message message = session.createTextMessage(serializer.serialiseerNaarString(selectieTaakResultaat));
producer.send(message);
return null;
};
publiceer(selectieTaakResultaatJmsTemplate, producerCallback, () -> "fout in verzenden berichten naar selectie taak resultaat queue");
}