本文整理汇总了Java中javax.jms.ObjectMessage类的典型用法代码示例。如果您正苦于以下问题:Java ObjectMessage类的具体用法?Java ObjectMessage怎么用?Java ObjectMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectMessage类属于javax.jms包,在下文中一共展示了ObjectMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
@Override
public void onMessage(Message message) {
try {
ObjectMessage objectMessage = (ObjectMessage) message;
HandlingEventRegistrationAttempt attempt
= (HandlingEventRegistrationAttempt) objectMessage.getObject();
handlingEventService.registerHandlingEvent(
attempt.getCompletionTime(),
attempt.getTrackingId(),
attempt.getVoyageNumber(),
attempt.getUnLocode(),
attempt.getType());
} catch (JMSException | CannotCreateHandlingEventException e) {
// Poison messages will be placed on dead-letter queue.
throw new RuntimeException("Error occurred processing message", e);
// } catch (JMSException e) {
// logger.log(Level.SEVERE, e.getMessage(), e);
}
}
开发者ID:RETIT,项目名称:continuous-performance-evaluation,代码行数:20,代码来源:HandlingEventRegistrationAttemptConsumer.java
示例2: onMessageErrorHandling
import javax.jms.ObjectMessage; //导入依赖的package包/类
@Test
public void onMessageErrorHandling() throws Exception {
// given
PayloadStub payload = new PayloadStub();
payload.setExecuteCauseException(true);
TaskMessage taskMessage = new TaskMessage(HandlerStub.class, payload);
ObjectMessage messageMock = mock(ObjectMessage.class);
when(messageMock.getObject()).thenReturn(taskMessage);
// when
listener.onMessage(messageMock);
// then
assertTrue(payload.isHandledErrorSuccessfully());
}
示例3: onMessageErrorHandlingFailed
import javax.jms.ObjectMessage; //导入依赖的package包/类
@Test
public void onMessageErrorHandlingFailed() throws Exception {
// given
PayloadStub payload = new PayloadStub();
payload.setExecuteCauseException(true);
payload.setHandleErrorCauseException(true);
TaskMessage taskMessage = new TaskMessage(HandlerStub.class, payload);
ObjectMessage messageMock = mock(ObjectMessage.class);
when(messageMock.getObject()).thenReturn(taskMessage);
// when
listener.onMessage(messageMock);
// then
assertTrue(payload.isExecuted());
assertFalse(payload.isExecutedSuccessfully());
assertTrue(payload.isErrorHandled());
assertFalse(payload.isHandledErrorSuccessfully());
}
示例4: onMessageInvalidMessageObjectInstance
import javax.jms.ObjectMessage; //导入依赖的package包/类
@Test
public void onMessageInvalidMessageObjectInstance() throws Exception {
// given
listener = spy(listener);
Serializable wrongMessage = mock(Serializable.class);
ObjectMessage messageMock = mock(ObjectMessage.class);
when(messageMock.getObject()).thenReturn(wrongMessage);
// when
listener.onMessage(messageMock);
// then
verify(listener, times(1)).logIllegalArgumentExceptionError(
any(IllegalArgumentException.class));
}
示例5: sendObjectMsgSingleSession
import javax.jms.ObjectMessage; //导入依赖的package包/类
private void sendObjectMsgSingleSession(List<? extends Serializable> objectsToSend) throws JMSException {
Session session = null;
Connection conn = null;
try {
conn = qFactory.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
for (Serializable objectToSend : objectsToSend) {
ObjectMessage msg = session.createObjectMessage();
msg.setObject(objectToSend);
producer.send(msg);
}
} finally {
closeSession(session);
closeConnection(conn);
}
}
示例6: publishMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
/**
* Publish message.
*
* @param event the event
* @throws JMSException the jMS exception
*/
public void publishMessage(final BasicEvent event) throws JMSException {
if (System.currentTimeMillis() > lastFailureTimestamp) {
publishedCounter.incrementAndGet();
int shard = (int) (event.getManifestId() % poolsize);
try {
producers[shard].send(session -> {
ObjectMessage message = session.createObjectMessage(event);
message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
message.setLongProperty("ciId", event.getCiId());
message.setLongProperty("manifestId", event.getManifestId());
message.setStringProperty("source", event.getSource());
if (logger.isDebugEnabled()) {
logger.debug("Published: ciId:" + event.getCiId() + "; source:" + event.getSource());
}
return message;
});
lastFailureTimestamp = -1;
} catch (JmsException exception) {
logger.warn("There was an error sending a message. Discarding messages for " + mqConnectionThreshold + " ms");
lastFailureTimestamp = System.currentTimeMillis() + mqConnectionThreshold;
}
}
}
示例7: onMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
/**
* takes the jms message
*/
public void onMessage(Message msg) {
try {
if (msg instanceof ObjectMessage) {
BasicEvent event = (BasicEvent)((ObjectMessage)msg).getObject();
if (logger.isDebugEnabled() || cisToLog.contains(event.getCiId())) {
logger.info(gson.toJson(event));
}
sensorHeartBeat.timeStampIt(event.getChannel());
sensorHeartBeat.timeStampIt(BasicEvent.DEFAULT_CHANNEL);
sensor.sendCEPEvent(event);
}
msg.acknowledge();
} catch (JMSException e) {
logger.info("caught Exception in onMessage",e);
}
}
示例8: testOnMessageExceptionCase
import javax.jms.ObjectMessage; //导入依赖的package包/类
@Test
/*exception shall not come out, we force it
* but the code eats it */
public void testOnMessageExceptionCase() throws Exception{
SensorListener listen = new SensorListener();
Sensor sensorThrower = mock(Sensor.class);
listen.setSensor(sensorThrower);
listen.setSensorHeartBeat(mock(SensorHeartBeat.class));
ObjectMessage msg = mock(ObjectMessage.class);
doThrow(new JMSException("mock")).when(msg).acknowledge();
BasicEvent event = mock(BasicEvent.class);
when(msg.getObject()).thenReturn(event);
listen.onMessage(msg);
}
示例9: onObjectMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
/**
* sends an Object message instead of Text; should be ok
* it will get logged
*/
@Test
public void onObjectMessage() {
ObjectMessage objectMessage = mock(ObjectMessage.class);
NotificationMessage notificationMessage = new NotificationMessage();
notificationMessage.setTimestamp(1L);
notificationMessage.setText("mock-text");
try {
when(objectMessage.getObject()).thenReturn(notificationMessage);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例10: send
import javax.jms.ObjectMessage; //导入依赖的package包/类
/**
* Sends a message to the myWMS application inside the application
* server.
*
* @param mfcMessage the message to be send
* @throws JMSException
* @throws NamingException
*/
public void send(MFCMessage mfcMessage)
throws JMSException,
NamingException
{
// create the jms session
QueueSession session =
connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// lookup of the jms queue over jndi
Queue outputQueue =
(Queue) context.lookup("queue/" + OUTPUT_QUEUE_NAME);
// create the message publisher
QueueSender sender = session.createSender(outputQueue);
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(mfcMessage);
objectMessage.setJMSTimestamp(System.currentTimeMillis());
sender.send(objectMessage);
sender.close();
session.close();
}
示例11: onMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
public void onMessage(Message msg) {
try {
ObjectMessage om = (ObjectMessage)msg;
String operation = om.getStringProperty("operation");
Object obj = om.getObject();
String rashodCode = om.getStringProperty("rashodCode");
log.info("onMessage:" +operation+ "operation");
if (obj instanceof Record) {
Record rec = (Record)obj;
if ("add".equals(operation)) {
indexer.add(rec, rashodCode);
log.info("Record added, ID: " + rec.getRecordID());
} else if ("update".equals(operation)) {
indexer.update(rec, rashodCode);
log.info("Record updated, ID: " + rec.getRecordID());
}
}
else if ((obj instanceof Integer) && "delete".equals(operation)) {
Integer recID = (Integer)obj;
indexer.delete(recID);
log.info("Record deleted, ID: " + recID);
}
} catch (JMSException e) {
log.fatal(e);
}
}
示例12: onMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onMessage(final Message message) {
if (message instanceof ObjectMessage) {
final ObjectMessage msg = (ObjectMessage) message;
try {
final Serializable object = msg.getObject();
if (object instanceof EmailMessage) {
send((EmailMessage) object);
} else {
throw new IWSException(IWSErrors.ERROR, "Not a proper e-mail message.");
}
} catch (JMSException e) {
throw new IWSException(IWSErrors.ERROR, "Sending the email message failed.", e);
}
}
}
示例13: receiveMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
@JmsListener(destination = Queue.EMAIL_QUEUE, containerFactory = "jmsContainerFactory")
public void receiveMessage(Message message) {
if (message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
try {
if (objectMessage.getObject() instanceof EmailJmsMessage) {
try {
EmailJmsMessage emailJmsMessage = (EmailJmsMessage) objectMessage.getObject();
emailMessage.sendEmail(emailJmsMessage.getHtml(), emailJmsMessage.getAttachments(),
emailJmsMessage.getRecipient(), emailJmsMessage.getSubject());
} catch (Exception e) {
logger.error("Email messaging exception", e);
}
}
} catch (JMSException ex) {
logger.error("JMSException thrown during Email JMS message acknowledgment:", ex);
}
} else {
logger.error("JMS: not an object message - nothing to do");
}
}
示例14: to
import javax.jms.ObjectMessage; //导入依赖的package包/类
@Override
public void to(JmsDestination target) {
try {
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = createFunction.apply(connection);
Destination destination = target.createDestination(session);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
if (this.expirationTime != null) {
producer.setTimeToLive(this.expirationTime);
}
ObjectMessage message = session.createObjectMessage(object);
producer.send(message);
session.close();
connection.close();
} catch (JMSException e) {
logger.error("Error while sending object to AMQ destination", e);
}
}
示例15: onMessage
import javax.jms.ObjectMessage; //导入依赖的package包/类
@Override
public void onMessage(Message message) {
ObjectMessage msg = (ObjectMessage) message;
try {
Order order = (Order) msg.getObject();
System.out.println("Got message from queue receiver==>" + order);
// Send response
OrderResponse orderResponse = new OrderResponse();
orderResponse.setItemCode(order.getItemCode());
orderResponse.setOrderQuantity(order.getQuantity());
ReorderResponseMessageSender.sendMessage(orderResponse);
} catch (JMSException | NamingException e) {
e.printStackTrace();
}
}