Example usage for org.springframework.integration.core MessagingTemplate sendAndReceive

List of usage examples for org.springframework.integration.core MessagingTemplate sendAndReceive

Introduction

In this page you can find the example usage for org.springframework.integration.core MessagingTemplate sendAndReceive.

Prototype

@Override
    public Message<?> sendAndReceive(MessageChannel destination, Message<?> requestMessage) 

Source Link

Usage

From source file:com.apress.prospringintegration.webservice.client.TicketWebServiceDomClient.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("client.xml");

    MessageChannel channel = context.getBean("ticketRequests", MessageChannel.class);

    String body = String.format(bodyTemplate, "Message Broker Down", "emergency");
    System.out.println(body);//from w  ww  .  j  a  va  2s.c  o m
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    Message<?> message = messagingTemplate.sendAndReceive(channel, MessageBuilder.withPayload(body).build());

    System.out.println(message.getPayload());

}

From source file:uk.co.jemos.experiments.integration.HelloWorldApp.java

public static void main(String[] args) {

    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class);
    MessageChannel inputChannel = context.getBean("podamInputChannel", MessageChannel.class);

    Message<Object> intMessage = MessageBuilder.withPayload(new Object())
            .setHeader("type", int.class.toString()).build();
    Message<Object> boolMessage = MessageBuilder.withPayload(new Object())
            .setHeader("type", boolean.class.toString()).build();
    Message<Object> stringMessage = MessageBuilder.withPayload(new Object())
            .setHeader("type", String.class.getName()).build();

    MessagingTemplate template = new MessagingTemplate();
    Message reply = template.sendAndReceive(inputChannel, intMessage);
    logger.info(reply.getPayload());/*from w w  w. j  a  va 2  s.  c  o  m*/
    reply = template.sendAndReceive(inputChannel, boolMessage);
    logger.info(reply.getPayload());
    reply = template.sendAndReceive(inputChannel, stringMessage);
    logger.info(reply.getPayload());

    context.close();

}

From source file:com.apress.prospringintegration.webservice.client.TicketWebServiceMarshallingClient.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("client.xml");

    MessageChannel channel = context.getBean("ticketRequests", MessageChannel.class);

    MessagingTemplate messagingTemplate = new MessagingTemplate();

    TicketRequest tr = new TicketRequest();
    tr.setDescription("Message Broker Down");
    tr.setPriority(PriorityType.EMERGENCY);
    System.out.printf("Ticket Request: %s [priority: %s] %n", tr.getDescription(), tr.getPriority());
    Message<TicketRequest> ticketRequestMessage = MessageBuilder.withPayload(tr).build();

    @SuppressWarnings("unchecked")
    Message<TicketResponse> message = (Message<TicketResponse>) messagingTemplate.sendAndReceive(channel,
            ticketRequestMessage);/* w ww.j a va  2s  .com*/

    Ticket ticket = message.getPayload().getTicket();
    System.out.printf("Ticket Response: %s [id: %d] [priority: %s] [date: %s]%n", ticket.getDescription(),
            ticket.getTicketId(), ticket.getPriority(), ticket.getIssueDateTime());

}

From source file:org.apilytic.currency.service.impl.DefaultTwitterService.java

/** {@inheritDoc} */
@Override/*  w w w .  j a  va2  s.c  o m*/
public boolean isTwitterAdapterRunning() {

    final MessagingTemplate m = new MessagingTemplate();
    final Message<String> operation = MessageBuilder.withPayload("@twitter.isRunning()").build();

    @SuppressWarnings("unchecked")
    Message<Boolean> reply = (Message<Boolean>) m.sendAndReceive(channel, operation);

    return reply.getPayload();

}