本文整理汇总了Java中javax.jms.TextMessage.getText方法的典型用法代码示例。如果您正苦于以下问题:Java TextMessage.getText方法的具体用法?Java TextMessage.getText怎么用?Java TextMessage.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.TextMessage
的用法示例。
在下文中一共展示了TextMessage.getText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
@Override
public void onMessage(Message message) {
try {
if (message instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) message;
byte[] data = new byte[(int) bytesMessage.getBodyLength()];
bytesMessage.readBytes(data);
LOG.info("Message received {}", new String(data));
} else if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
LOG.info("Message received {}", text);
}
} catch (JMSException jmsEx) {
jmsEx.printStackTrace();
}
}
示例2: onMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
/**
* Implementation of <code>MessageListener</code>.
*/
public void onMessage(Message message) {
try {
int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT);
if (message instanceof TextMessage) {
TextMessage tm = (TextMessage)message;
String msg = tm.getText();
System.out.println("Processed message '{}'. value={}"+ msg+ messageCount);
counter.incrementAndGet();
}
} catch (JMSException e) {
e.printStackTrace();
}
}
示例3: handleMessage
import javax.jms.TextMessage; //导入方法依赖的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);
}
}
示例4: onMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
@Override
public void onMessage(final Message message) {
BrpNu.set(DatumUtil.nuAlsZonedDateTime());
try {
LOGGER.debug("onMessage");
LOGGER.info("Geen personen vallen binnen de selectie Sv11 wordt uitgestuurd.");
final TextMessage textMessage = (TextMessage) message;
final String text = textMessage.getText();
final MaakSelectieResultaatTaak
maakSelectieResultaatTaak =
JSON_STRING_SERIALISEERDER.deserialiseerVanuitString(text, MaakSelectieResultaatTaak.class);
selectieGeenResultaatGbaBerichtWriter.verstuurSv11Bericht(maakSelectieResultaatTaak);
} catch (JMSException e) {
LOGGER.error("error on message", e);
}
}
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:17,代码来源:MaakSelectieGeenResultaatNetwerkTaakQueueMessageListener.java
示例5: onMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
@Override
public void onMessage(Message msg) {
if (msg instanceof TextMessage) {
TextMessage textMessage = (TextMessage) msg;
String text = "";
try {
text = textMessage.getText();
} catch (JMSException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
System.out.println("Received: " + text);
} else {
System.out.println("Received: " + msg);
}
}
示例6: startConsumer
import javax.jms.TextMessage; //导入方法依赖的package包/类
private void startConsumer() {
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination;
if ("topic".equalsIgnoreCase(destinationType)) {
destination = session.createTopic(destinationName);
} else {
destination = session.createQueue(destinationName);
}
consumer = session.createConsumer(destination);
isStarted.compareAndSet(false, true);
while (true) {
Message message = consumer.receive();
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
if (isRecording.get()) {
addData(message, text);
}
counter.incrementAndGet();
}
}
} catch (Exception e) {
//e.printStackTrace();
} finally {
terminate();
}
}
示例7: onMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
@Override
public void onMessage(final Message message) {
BrpNu.set(DatumUtil.nuAlsZonedDateTime());
try {
LOGGER.debug("onMessage");
final TextMessage textMessage = (TextMessage) message;
final String text = textMessage.getText();
final MaakSelectieResultaatTaak
maakSelectieResultaatTaak =
JSON_STRING_SERIALISEERDER.deserialiseerVanuitString(text, MaakSelectieResultaatTaak.class);
final SoortSelectie soortSelectie = maakSelectieResultaatTaak.getSoortSelectie();
if (soortSelectie == SoortSelectie.STANDAARD_SELECTIE) {
maakSelectieResultaatTaakVerwerkerServiceImpl.verwerk(maakSelectieResultaatTaak);
} else if (soortSelectie == SoortSelectie.SELECTIE_MET_PLAATSING_AFNEMERINDICATIE
|| soortSelectie == SoortSelectie.SELECTIE_MET_VERWIJDERING_AFNEMERINDICATIE) {
afnemerindicatieMaakSelectieResultaatTaakVerwerkerServiceImpl.verwerk(maakSelectieResultaatTaak);
}
} catch (JMSException e) {
LOGGER.error("error on message", e);
}
}
示例8: main
import javax.jms.TextMessage; //导入方法依赖的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 MessageConsumer from the Session to the Topic or Queue
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
Message message = consumer.receive(1000);
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
System.out.println("Received: " + text);
} else {
System.out.println("Received: " + message);
}
consumer.close();
session.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: run
import javax.jms.TextMessage; //导入方法依赖的package包/类
public void run() {
try {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
connection.setExceptionListener(this);
// 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 MessageConsumer from the Session to the Topic or Queue
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
Message message = consumer.receive(1000);
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
System.out.println("Received: " + text);
} else {
System.out.println("Received: " + message);
}
consumer.close();
session.close();
connection.close();
} catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
示例10: requeueFailedMessages
import javax.jms.TextMessage; //导入方法依赖的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);
}
}
示例11: checkActiveMQJMSProtocol
import javax.jms.TextMessage; //导入方法依赖的package包/类
public String checkActiveMQJMSProtocol(String messageAsString,
String url) throws JMSException {
ActiveMQConnectionFactory activeMQConnectionFactory =
new ActiveMQConnectionFactory(String.format("tcp://%s", url));
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(activeMQConnectionFactory);
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
Destination destination = new ActiveMQQueue("myQueue");
jmsTemplate.setDefaultDestination(destination);
jmsTemplate.send(destination, t -> {
TextMessage message = t.createTextMessage(messageAsString);
return message;
});
TextMessage receivedMessage = (TextMessage) jmsTemplate.receive(destination);
return receivedMessage.getText();
}
示例12: onMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
@Override
public void onMessage(final Message message) {
BrpNu.set(DatumUtil.nuAlsZonedDateTime());
try {
LOGGER.debug("onMessage");
final TextMessage textMessage = (TextMessage) message;
final String text = textMessage.getText();
final SelectieFragmentSchrijfBericht
selectieSchrijfTaak =
JSON_STRING_SERIALISEERDER.deserialiseerVanuitString(text, SelectieFragmentSchrijfBericht.class);
selectieFragmentSchrijfTaakVerwerkerService.verwerk(selectieSchrijfTaak);
} catch (JMSException e) {
LOGGER.error("error on message", e);
}
}
示例13: waitForNextMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
public String waitForNextMessage() {
try {
TextMessage tm = (TextMessage) consumer.receive();
return tm.getText();
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
示例14: onMessage
import javax.jms.TextMessage; //导入方法依赖的package包/类
@Override
public void onMessage(Message message) {
try {
TextMessage tm = (TextMessage) message;
String json = tm.getText();
logger.info("*** received message: {}", json);
Shipment shipment = JsonUtils.fromJson(json, Shipment.class);
shipments.add(shipment);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例15: startConsumer
import javax.jms.TextMessage; //导入方法依赖的package包/类
public void startConsumer() {
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = null;
if ("topic".equalsIgnoreCase(destinationType)) {
destination = session.createTopic(destinationName);
}
else {
destination = session.createQueue(destinationName);
}
consumer = session.createConsumer(destination);
isStarted.compareAndSet(false, true);
while (true) {
Message message = consumer.receive();
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
//System.out.println("Received: " + text);
counter.incrementAndGet();
if (isRecording.get()) {
addData(message, text);
}
}
}
} catch (Exception e) {
//e.printStackTrace();
} finally {
terminate();
}
}