Package org.servicemix.examples

Examples of org.servicemix.examples.ReceiverComponent


        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);
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

        Object receiverFlow = receiverContainer.getFlow();
        assertTrue(receiverFlow instanceof JMSFlow);

        Thread.sleep(2000);
       
        receiver = new ReceiverComponent();
        sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));
View Full Code Here

      receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }

    public void testClusteredInOnly() throws Exception {
        final SenderComponent sender = new SenderComponent();
        final ReceiverComponent receiver1 =  new ReceiverComponent();
        final ReceiverComponent receiver2 =  new ReceiverComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver1));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver2));
        Thread.sleep(1000);

        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        assertTrue(receiver1.getMessageList().hasReceivedMessage());
        assertTrue(receiver2.getMessageList().hasReceivedMessage());
        receiver1.getMessageList().flushMessages();
        receiver2.getMessageList().flushMessages();
       
        senderContainer.deactivateComponent("receiver");
        Thread.sleep(1000);
       
        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        assertFalse(receiver1.getMessageList().hasReceivedMessage());
        assertTrue(receiver2.getMessageList().hasReceivedMessage());
        receiver1.getMessageList().flushMessages();
        receiver2.getMessageList().flushMessages();
       
        senderContainer.activateComponent(new ActivationSpec("receiver", receiver1));
        receiverContainer.deactivateComponent("receiver");
        Thread.sleep(1000);
       
        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        assertTrue(receiver1.getMessageList().hasReceivedMessage());
        assertFalse(receiver2.getMessageList().hasReceivedMessage());
        receiver1.getMessageList().flushMessages();
        receiver2.getMessageList().flushMessages();
    }
View Full Code Here

   
    public void testExternalRouting() throws Exception {
        JBIContainer container = new JBIContainer();
        container.init();
        container.start();
        ReceiverComponent receiver = new ReceiverComponent() {
            protected void init() throws JBIException {
                ServiceEndpoint ep = new ExternalEndpoint(getService(), getEndpoint());
                getContext().registerExternalEndpoint(ep);
                setService(null);
                setEndpoint(null);
            }

            public ServiceEndpoint resolveEndpointReference(DocumentFragment fragment) {
                try {
                    SourceTransformer st = new SourceTransformer();
                    String xml = st.toString(fragment);
                    return (ServiceEndpoint) new XStream(new DomDriver()).fromXML(xml);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        };
        container.activateComponent(new ActivationSpec("receiver", receiver));
        ServiceMixClient client = new DefaultServiceMixClient(container);
        ServiceEndpoint[] endpoints = client.getContext().getExternalEndpoints(null);
        assertNotNull(endpoints);
        assertEquals(1, endpoints.length);
        assertNull(client.getContext().getEndpointDescriptor(endpoints[0]));
        ServiceEndpoint se = client.getContext().resolveEndpointReference(endpoints[0].getAsReference(null));
        assertNull(client.getContext().getEndpointDescriptor(se));
        InOnly me = client.createInOnlyExchange();
        me.setEndpoint(se);
        client.send(me);
        receiver.getMessageList().assertMessagesReceived(1);
    }
View Full Code Here

    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));
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));
View Full Code Here

        receiverContainer.setFlowName("cluster");
        receiverContainer.init();
        receiverContainer.start();
        ClusterFlow receiverFlow = (ClusterFlow)receiverContainer.getFlow();

        receiver = new ReceiverComponent();
        sender = new SenderComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));
View Full Code Here

        broker.stop();
    }
   
    public void testInOnly() throws Exception {
        final SenderComponent sender = new SenderComponent();
        final ReceiverComponent receiver =  new ReceiverComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));

        Thread.sleep(5000);

        sender.sendMessages(NUM_MESSAGES);
        Thread.sleep(3000);
        receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }
View Full Code Here

        receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }
   
    public void testTxInOnly() throws Exception {
        final SenderComponent sender = new SenderComponent();
        final ReceiverComponent receiver =  new ReceiverComponent();
        sender.setResolver(new ServiceNameEndpointResolver(ReceiverComponent.SERVICE));

        senderContainer.activateComponent(new ActivationSpec("sender", sender));
        receiverContainer.activateComponent(new ActivationSpec("receiver", receiver));

        Thread.sleep(5000);
       
      senderContainer.setAutoEnlistInTransaction(true);
        tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
                try {
                    sender.sendMessages(NUM_MESSAGES);
                } catch (JBIException e) {
                    throw new RuntimeJBIException(e);
                }
          return null;
        }
        });
      Thread.sleep(3000);
      receiver.getMessageList().assertMessagesReceived(NUM_MESSAGES);
    }
View Full Code Here

TOP

Related Classes of org.servicemix.examples.ReceiverComponent

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.