Example usage for org.springframework.messaging.support MessageBuilder withPayload

List of usage examples for org.springframework.messaging.support MessageBuilder withPayload

Introduction

In this page you can find the example usage for org.springframework.messaging.support MessageBuilder withPayload.

Prototype

public static <T> MessageBuilder<T> withPayload(T payload) 

Source Link

Document

Create a new builder for a message with the given payload.

Usage

From source file:com.tvd.common.channel.HelloWorldExample.java

public static void main(String args[]) {
    String cfg = "channel/context.xml";
    @SuppressWarnings("resource")
    ApplicationContext context = new ClassPathXmlApplicationContext(cfg);
    MessageChannel channel = context.getBean("names", MessageChannel.class);
    Message<String> message = MessageBuilder.withPayload("World").build();
    channel.send(message);//  w ww  .j a v a2 s  .  com
}

From source file:org.musa.tcpclients.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//from   ww  w.j a v a  2s.c  o m
 */
public static void main(final String... args) {

    final Scanner scanner = new Scanner(System.in);

    //context.getB
    GenericXmlApplicationContext context = Main.setupContext();
    WarpGateway gateway = (WarpGateway) context.getBean("gw");

    System.out.println("running.\n\n");

    System.out.println("Please enter numbers to spawn spacemarines :");
    System.out.println("1: Gabriel Loken");
    System.out.println("2: Nathaniel Garro");
    System.out.println("3: Ezekyl Abaddon");
    System.out.println("4: Sanguinius");
    System.out.println("5: Lucius");

    System.out.println("\t- Entering q will quit the application");
    System.out.print("\n");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        } else {

            SpaceMarine gabriel = new SpaceMarine("Gabriel Loken", "Luna Wolves", 500, SMRank.CaptainBrother,
                    SMLoyalty.Loyalist, 100);
            SpaceMarine garro = new SpaceMarine("Nathaniel Garro", "Deathguard", 500, SMRank.CaptainBrother,
                    SMLoyalty.Loyalist, 100);
            SpaceMarine ezekyl = new SpaceMarine("Ezekyl Abaddon", "Black Legion", 500, SMRank.CaptainBrother,
                    SMLoyalty.Traitor, 100);
            SpaceMarine sanguinius = new SpaceMarine("Sanguinius", "Blood angels", 999, SMRank.Primarch,
                    SMLoyalty.Loyalist, 600);
            SpaceMarine lucius = new SpaceMarine("Lucius", "Emperor's children", 500, SMRank.SwordMaster,
                    SMLoyalty.Traitor, 700);

            SpaceMarine[] spaceMarines = { gabriel, garro, ezekyl, sanguinius, lucius };
            int max_id = spaceMarines.length;

            int num = 0; //input
            try {
                num = Integer.parseInt(input);
            } catch (NumberFormatException e) {
                System.out.println("unable to parse value");
            }
            if (num >= max_id) {
                System.out.println("no such spacemarine, using Loken");
                num = 0;
            }

            System.out.println("teleporting " + spaceMarines[num].getName() + "....");

            Message<SpaceMarine> m = MessageBuilder.withPayload(spaceMarines[num]).build();

            //context.
            String reply = (String) gateway.send(m);
            System.out.println(reply);

        }
    }

    System.out.println("Exiting application...bye.");
    System.exit(0);

}

From source file:com.example.journal.teller.StreamJournal.java

@Override
public boolean debit(JournalEntry entry) {
    return source.output().send(MessageBuilder.withPayload(entry).setHeader("X-Journal-Type", "debit").build());
}

From source file:gov.grantsolutions.CommitmentEvent.java

public void change(String event, String currentState) {
    commitmentStateMachineHandler.handleEventWithState(MessageBuilder.withPayload(event).build(), currentState);
}

From source file:com.example.journal.teller.StreamJournal.java

@Override
public boolean credit(JournalEntry entry) {
    return source.output()
            .send(MessageBuilder.withPayload(entry).setHeader("X-Journal-Type", "credit").build());
}

From source file:org.zrgs.spring.statemachine.cdplayer.CdPlayer.java

public void load(Cd cd) {
    stateMachine.sendEvent(MessageBuilder.withPayload(Application.Events.LOAD)
            .setHeader(Application.Variables.CD.toString(), cd).build());
}

From source file:s2gx2014.messaging.Application.java

@Override
public void run(String... strings) throws Exception {
    logger.info("Sending message");
    messagingTemplate.send("s2gx2014", MessageBuilder.withPayload("Hello SpringOne 2014").build());
}

From source file:org.thingsplode.server.bus.executors.AbstractRequestResponseExecutor.java

public Message<?> execute(Message<?> msg) {
    AbstractRequest req = (AbstractRequest) msg.getPayload();
    try {//from w w  w  .j ava  2s  .  c o m
        RSP response = executeImpl((REQ) msg.getPayload(), msg.getHeaders(),
                getDeviceRepo().findByIdentification(req.getDeviceId()));
        if (response != null) {
            return MessageBuilder.withPayload(configureCommonFields(req, response)).build();
        } else {
            return MessageBuilder
                    .withPayload(configureCommonFields(req,
                            new Response<>(req.getMessageId(), ExecutionStatus.DECLINED,
                                    ResponseCode.REQUIRED_RESPONSE_IS_MISSING, "return payload value is null")))
                    .build();
        }

    } catch (SrvExecutionException ex) {
        logger.error(ex.getMessage(), ex);
        //msgTemplate.send(MessageBuilder.withPayload(new ErrorMessage(ex.getExecutionStatus(), ex.getResponseCode(), ex)).build());
        return MessageBuilder.withPayload(configureCommonFields(req, new Response<>(req.getMessageId(),
                ex.getExecutionStatus(), ex.getResponseCode(), ex.getMessage()))).build();
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        //msgTemplate.send(MessageBuilder.withPayload(new ErrorMessage(ExecutionStatus.DECLINED, ResponseCode.INTERNAL_SYSTEM_ERROR, ex)).build());
        return MessageBuilder
                .withPayload(configureCommonFields(req, new Response<>(req.getMessageId(),
                        ExecutionStatus.DECLINED, determineResponseCode(ex), determineExceptionMessage(ex))))
                .build();
    }
}

From source file:org.thingsplode.server.bus.executors.AbstractSyncExecutor.java

public void process(Message<?> msg) {
    AbstractRequest req = (AbstractRequest) msg.getPayload();
    Device callerDevice = getDeviceRepo().findByIdentification(req.getDeviceId());
    if (callerDevice == null) {
        throw new IllegalStateException(String.format("The device identified by id [%s] is not registered",
                req.getDeviceId() != null ? req.getDeviceId() : "<NULL>"));
    }//  w  w  w  . j  av  a  2s. co m
    try {
        executeImpl((REQ) msg.getPayload(), msg.getHeaders(), callerDevice);
    } catch (SrvExecutionException ex) {
        logger.error(ex.getMessage(), ex);
        getMsgTemplate().send(MessageBuilder
                .withPayload(new ErrorMessage(ex.getExecutionStatus(), ex.getResponseCode(), ex)).build());
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        getMsgTemplate().send(MessageBuilder
                .withPayload(new ErrorMessage(ExecutionStatus.DECLINED, determineResponseCode(ex), ex))
                .build());
    }
}

From source file:org.zrgs.spring.statemachine.cdplayer.CdPlayer.java

public void forward() {
    stateMachine.sendEvent(MessageBuilder.withPayload(Application.Events.FORWARD)
            .setHeader(Application.Headers.TRACKSHIFT.toString(), 1).build());
}