-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultGatewayExample.kt
84 lines (68 loc) · 2.1 KB
/
DefaultGatewayExample.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.example.springintegrationdemo2
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.integration.annotation.*
import org.springframework.integration.channel.DirectChannel
import org.springframework.integration.test.context.SpringIntegrationTest
import org.springframework.messaging.handler.annotation.Payload
import org.springframework.stereotype.Component
@SpringIntegrationTest
@SpringBootTest
class DefaultGatewayExampleTest {
@Autowired
lateinit var cafeGateway: CafeGateway
@org.junit.jupiter.api.Test
internal fun sample() {
cafeGateway.coffeeSupplier(10)
}
}
@MessagingGateway
interface CafeGateway {
@Gateway(requestChannel = "order",
replyTimeout = 1,
requestTimeout = 1)
fun coffeeSupplier(@Payload quantity: Int): Coffee
}
data class Coffee(
val quantity: Int
)
@Configuration
class GatewayConfig {
@Bean
fun order(): DirectChannel {
return DirectChannel()
}
@Bean
fun supplier(): DirectChannel {
return DirectChannel()
}
@Bean
fun anotherSupplier(): DirectChannel {
return DirectChannel()
}
}
@Component
class MessageProcessor(
@Qualifier("order")
val order: DirectChannel,
@Qualifier("supplier")
val supplier: DirectChannel
) {
@ServiceActivator(inputChannel = "order", outputChannel = "supplier")
fun sendMessageToGateway(quantity: Int): Coffee {
log.info("Order received for the quantity: $quantity")
log.info("Coffees sent for the request")
return Coffee(quantity = quantity)
}
@ServiceActivator(inputChannel = "supplier")
fun receivedChannel(@Payload coffee: Coffee): Unit {
log.info("Got the Coffees from the supplier: $coffee")
}
companion object {
private val log = LoggerFactory.getLogger(this::class.java)
}
}