public void testInOnlySync() throws Exception { // Create thread to answer new Thread( new Runnable() { public void run() { try { // Provider side InOnly mep = (InOnly) provider.getChannel().accept(10000L); assertNotNull(mep); assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); mep.setStatus(ExchangeStatus.DONE); provider.getChannel().send(mep); } catch (Exception e) { e.printStackTrace(); fail(); } } }) .start(); // Send message exchange MessageExchangeFactory mef = consumer.getChannel().createExchangeFactory(endpoint); InOnly mec = mef.createInOnlyExchange(); NormalizedMessage m = mec.createMessage(); m.setContent(new StreamSource(new ByteArrayInputStream(PAYLOAD.getBytes()))); mec.setInMessage(m); consumer.getChannel().sendSync(mec, 10000L); assertEquals(ExchangeStatus.DONE, mec.getStatus()); // Nothing left assertNull(consumer.getChannel().accept(10L)); // receive in assertNull(provider.getChannel().accept(10L)); // receive in }
@Override public void sendEvent(Event event, String targetNamespace, String targetService) { try { QName service = new QName(targetNamespace, targetService); InOnly inOnly = new InOnlyImpl(UUID.randomUUID().toString()); inOnly.setService(service); inOnly.setOperation(new QName("event")); NormalizedMessage msg = inOnly.createMessage(); inOnly.setInMessage(msg); msgProperties.applyToMessage(msg); String xml = Transformer.toXml(event); msg.setContent(new StringSource(xml)); endpoint.sendSync(inOnly); } catch (MessagingException e) { throw new RuntimeException(e); } catch (SerializationException e) { throw new RuntimeException(e); } }
public void onMessage(MessageExchange messageExchange, NormalizedMessage message) throws MessagingException { if (messageExchange.getRole() == MessageExchange.Role.PROVIDER) { return; } NormalizedMessage in = messageExchange.getMessage("in"); try { NormalizedMessage out = messageExchange.createMessage(); transform(messageExchange, in, out); if (messageExchange instanceof InOut) { messageExchange.setMessage(out, OUT); } else { InOnly outExchange = exchangeFactory.createInOnlyExchange(); outExchange.setInMessage(out); deliveryChannel.sendSync(outExchange); } done(messageExchange); } catch (Exception e) { error(messageExchange, e); } }
public void testInOnly() throws Exception { // Send message exchange MessageExchangeFactory mef = consumer.getChannel().createExchangeFactory(endpoint); InOnly mec = mef.createInOnlyExchange(); NormalizedMessage m = mec.createMessage(); m.setContent(new StreamSource(new ByteArrayInputStream(PAYLOAD.getBytes()))); mec.setInMessage(m); consumer.getChannel().send(mec); // Provider side InOnly mep = (InOnly) provider.getChannel().accept(10L); assertNotNull(mep); assertEquals(ExchangeStatus.ACTIVE, mep.getStatus()); mep.setStatus(ExchangeStatus.DONE); provider.getChannel().send(mep); // Consumer side assertSame(mec, consumer.getChannel().accept(10L)); assertEquals(ExchangeStatus.DONE, mec.getStatus()); // Nothing left assertNull(consumer.getChannel().accept(10L)); // receive in assertNull(provider.getChannel().accept(10L)); // receive in }