This repository was archived by the owner on Jul 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Home
olegz edited this page Jun 15, 2011
·
114 revisions
Welcome to Spring Integration Scala DSL wiki!
Simple Message exchange between Point-to-Point channel (DirectChannel) and Service Activator
var integrationContext = SpringIntegrationContext()
val inputChannel = channel("inputChannel")
integrationContext <= {
inputChannel >>
activate("myService"){m:Message[String] => {println(m.getPayload)}}
}
integrationContext.init
inputChannel.send(new GenericMessage("==> Hello from Scala"))
In the above example ServiceActivator is provided with Scala function which simply prints the payload of the Message. You can also use Spring's Expression Language (SpEL). The equivalent SpEL-based Service Activator configuration would look like this:
activate("myService"){"T(java.lang.System).out.println(payload)"}
Simple Message exchange between asynchronous Point-to-Point channel (DirectChannel) and Service Activator
var integrationContext = SpringIntegrationContext()
val inputChannel = channel("inputChannel", executor(Executors.newFixedThreadPool(10)))
integrationContext <= {
inputChannel >>
activate("myService"){m:Message[String] => {println(m.getPayload)}}
}
integrationContext.init
inputChannel.send(new GenericMessage("==> Hello from Scala"))
The only difference between this sample and the previous one is that the Message Dispatcher used by the inputChannel is injected with an Executor.
Simple Message exchange with Queue Channel (channel which will buffer the messages until they are retrieved via explicit receive call)
var integrationContext = SpringIntegrationContext()
val inputChannel = channel("inputChannel")
val outputChannel = queue_channel("outputChannel", queue(5))
integrationContext <= {
inputChannel >>
activate("myService"){m:Message[String] => {m.getPayload.toUpperCase()}} >>
outputChannel
}
integrationContext.init
inputChannel.send(new GenericMessage("==> Hello from Scala"))
var outputMessage = outputChannel.receive
println("Output Message: " + outputMessage)
In the above sample outputChannel is configured as QueueChannel with queue capacity of 5. Service Activator produces an output Message and sends it to the outputChannel. The Message is received from the outputChannel by calling receive method
Simple Message exchange with Queue Channel and Polling Consumer
var integrationContext = SpringIntegrationContext()
val inputChannel = channel("inputChannel", executor())
val outputChannel = queue_channel("outputChannel", queue(5))
val resultChannel = queue_channel("resultChannel", queue())
integrationContext <= {
inputChannel >>
activate("myService"){m:Message[String] => {m.getPayload.toUpperCase()}} >>
outputChannel >>
activate("myTransformer", poller(1000, 5)){"'### ' + payload.toLowerCase() + ' ###'"} >>
resultChannel
}
integrationContext.init
inputChannel.send(new GenericMessage("==> Hello from Scala"))
var outputMessage = resultChannel.recieve
println("Output Message: " + outputMessage)