Package org.servicemix.examples

Examples of org.servicemix.examples.Receiver


    protected void runSimpleTest(final boolean syncSend, final boolean syncReceive) throws Exception {
        //final int numMessages = 1;
        final int numMessages = NUM_MESSAGES;
        final SenderComponent sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));
        final Receiver receiver;
        final Map delivered = new ConcurrentHashMap();
        if (syncReceive) {
          receiver = new ReceiverComponent() {
              public void onMessageExchange(MessageExchange exchange) throws MessagingException {
                try {
                  if (delivered.get(exchange.getExchangeId()) == null) {
                      System.err.println("Message delivery rolled back: " + exchange.getExchangeId());
                    delivered.put(exchange.getExchangeId(), Boolean.TRUE);
                    tm.setRollbackOnly();
                    done(exchange);
                  } else {
                      System.err.println("Message delivery accepted: " + exchange.getExchangeId());
                    super.onMessageExchange(exchange);
                  }
              } catch (Exception e) {
                throw new MessagingException(e);
              }
              }
          };
        } else {
          receiver = new AsyncReceiverPojo() {
              public void onMessageExchange(MessageExchange exchange) throws MessagingException {
                try {
                  if (delivered.get(exchange.getExchangeId()) == null) {
                      System.err.println("Message delivery rolled back: " + exchange.getExchangeId());
                      delivered.put(exchange.getExchangeId(), Boolean.TRUE);
                    tm.setRollbackOnly();
                        exchange.setStatus(ExchangeStatus.DONE);
                        getContext().getDeliveryChannel().send(exchange);
                  } else {
                      System.err.println("Message delivery accepted: " + exchange.getExchangeId());
                    super.onMessageExchange(exchange);
                  }
              } catch (Exception e) {
                throw new MessagingException(e);
              }
              }
          };
        }

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver));
       
        tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
                try {
                    sender.sendMessages(numMessages, syncSend);
                } catch (JBIException e) {
                    throw new RuntimeJBIException(e);
                }
          return null;
        }
        });
    //sender.sendMessages(NUM_MESSAGES, syncSend);
        receiver.getMessageList().assertMessagesReceived(numMessages);
    }
View Full Code Here


        MessageList messageList = receiver.getMessageList();
        assertMessagesReceived(messageList, messageCount);
    }

    protected MessageList assertMessagesReceived(String receiverName, int messageCount) throws Exception {
        Receiver receiver = (Receiver) getBean(receiverName);
        assertNotNull("receiver: " + receiverName + " not found in JBI container", receiver);

        MessageList messageList = receiver.getMessageList();
        assertMessagesReceived(messageList, messageCount);
        return messageList;
    }
View Full Code Here

      SenderListener sender = new SenderListener();
            ActivationSpec senderActivationSpec = new ActivationSpec("sender", sender);
            senderActivationSpec.setFailIfNoDestinationEndpoint(false);
      container.activateComponent(senderActivationSpec);
     
      Receiver receiver1 = new ReceiverComponent();
      container.activateComponent(createReceiverAS("receiver1", receiver1));
 
      Receiver receiver2 = new ReceiverComponent();
      container.activateComponent(createReceiverAS("receiver2", receiver2));
     
      sender.sendMessages(1, sync);
     
      Thread.sleep(100);
     
      assertEquals(1, receiver1.getMessageList().getMessageCount());
      assertEquals(1, receiver2.getMessageList().getMessageCount());
      assertEquals(0, sender.responses.size());
    } finally {
      container.shutDown();
    }
  }
View Full Code Here

        MessageList messageList = receiver.getMessageList();
        assertMessagesReceived(messageList, messageCount);
    }

    protected MessageList assertMessagesReceived(String receiverName, int messageCount) throws Exception {
        Receiver receiver = (Receiver) getBean(receiverName);
        assertNotNull("receiver: " + receiverName + " not found in JBI container", receiver);

        MessageList messageList = receiver.getMessageList();
        assertMessagesReceived(messageList, messageCount);
        return messageList;
    }
View Full Code Here

    protected abstract Flow createFlow();
   
    protected void runSimpleTest(final boolean syncSend, final boolean syncReceive) throws Exception {
        final SenderComponent sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));
        final Receiver receiver;
        if (syncReceive) {
          receiver = new ReceiverComponent();
        } else {
          receiver = new AsyncReceiverPojo();
        }

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver));
       
        tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
                try {
                    sender.sendMessages(NUM_MESSAGES, syncSend);
                } catch (JBIException e) {
                    throw new RuntimeJBIException(e);
                }
          return null;
        }
        });
        receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }
View Full Code Here

    }
   
    protected void runClusteredTest(final boolean syncSend, final boolean syncReceive) throws Exception {
        final SenderComponent sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));
        final Receiver receiver;
        if (syncReceive) {
          receiver = new ReceiverComponent();
        } else {
          receiver = new AsyncReceiverPojo();
        }

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));
        Thread.sleep(1000);
       
        tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
                try {
                    sender.sendMessages(NUM_MESSAGES, syncSend);
                } catch (JBIException e) {
                    throw new RuntimeJBIException(e);
                }
          return null;
        }
        });
        receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }
View Full Code Here

TOP

Related Classes of org.servicemix.examples.Receiver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.