Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Sending and receiving messages

olegz edited this page Jun 5, 2012 · 7 revisions

Messages could be sent and received using send(..) and senAndRecieve(..) methods exposed on message flow composition.

Sending Message

To only send a Message use send(..) method of the message flow

val messageFlow =
      filter{payload:String => payload == "hello"} -->
      transform{ m: Message[String] => m.getPayload().toUpperCase() } -->
      handle { m: Message[_] => println(m) }

messageFlow.send("hello")

You can also send a fully constructed Message by using MessageBuilder API provided by Spring Integration.

For example:

val message = MessageBuilder.withPayload("Hello").setHeader("foo", "foo").setHeader("bar", "bar").build
messageFlow.send(message)

The only reason why we support it is for interoperability with Java programs.

If you simply need to send a complex Message with payload and custom headers use headers parameter of the send(..) or sendAndReceive(..) methods.

For example:

messageFlow.send("hello", headers=Map("foo" -> "foo", "bar" -> "bar"))

Sending And Receiving Message

To send Message and receive a reply Message use sendAndReceive(..) method of the message flow

val transformingFlow = transform.using{payload:String => payload.toUpperCase}

val transformedMessagePayload = transformingFlow.sendAndReceive[String]("hello")

If you want to receive a full Message define it explicitly as a generic parameter of the method.

val transformedMessage = transformingFlow.sendAndReceive[Message[_]]("hello")

Use headers parameter to set any additional headers

val transformedMessage = transformingFlow.sendAndReceive[Message[_]]("hello", headers=Map("foo" -> "foo"))

Back to Reference