|
| 1 | +/* |
| 2 | + * Copyright 2020 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.integration.dsl |
| 18 | + |
| 19 | +import org.reactivestreams.Publisher |
| 20 | +import org.springframework.integration.core.MessageSource |
| 21 | +import org.springframework.integration.endpoint.MessageProducerSupport |
| 22 | +import org.springframework.integration.gateway.MessagingGatewaySupport |
| 23 | +import org.springframework.messaging.Message |
| 24 | +import org.springframework.messaging.MessageChannel |
| 25 | +import java.util.function.Consumer |
| 26 | + |
| 27 | +private fun buildIntegrationFlow(flowBuilder: IntegrationFlowBuilder, |
| 28 | + flow: (KotlinIntegrationFlowDefinition) -> Unit): IntegrationFlow { |
| 29 | + |
| 30 | + flow(KotlinIntegrationFlowDefinition(flowBuilder)) |
| 31 | + return flowBuilder.get() |
| 32 | +} |
| 33 | + |
| 34 | +/** |
| 35 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlow] lambdas. |
| 36 | + * |
| 37 | + * @author Artem Bilan |
| 38 | + */ |
| 39 | +fun integrationFlow(flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 40 | + IntegrationFlow { |
| 41 | + flow(KotlinIntegrationFlowDefinition(it)) |
| 42 | + } |
| 43 | + |
| 44 | +/** |
| 45 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 46 | + * `IntegrationFlows.from(Class<?>, Consumer<GatewayProxySpec>)` factory method. |
| 47 | + * |
| 48 | + * @author Artem Bilan |
| 49 | + */ |
| 50 | +inline fun <reified T> integrationFlow( |
| 51 | + crossinline gateway: GatewayProxySpec.() -> Unit = {}, |
| 52 | + flow: KotlinIntegrationFlowDefinition.() -> Unit): IntegrationFlow { |
| 53 | + |
| 54 | + val flowBuilder = IntegrationFlows.from(T::class.java) { gateway(it) } |
| 55 | + flow(KotlinIntegrationFlowDefinition(flowBuilder)) |
| 56 | + return flowBuilder.get() |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 61 | + * `IntegrationFlows.from(String, Boolean)` factory method. |
| 62 | + * |
| 63 | + * @author Artem Bilan |
| 64 | + */ |
| 65 | +fun integrationFlow(channelName: String, fixedSubscriber: Boolean = false, |
| 66 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 67 | + buildIntegrationFlow(IntegrationFlows.from(channelName, fixedSubscriber), flow) |
| 68 | + |
| 69 | +/** |
| 70 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 71 | + * `IntegrationFlows.from(MessageChannel)` factory method. |
| 72 | + * |
| 73 | + * @author Artem Bilan |
| 74 | + */ |
| 75 | +fun integrationFlow(channel: MessageChannel, flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 76 | + buildIntegrationFlow(IntegrationFlows.from(channel), flow) |
| 77 | + |
| 78 | +/** |
| 79 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 80 | + * `IntegrationFlows.from(MessageSource<*>, Consumer<SourcePollingChannelAdapterSpec>)` factory method. |
| 81 | + * |
| 82 | + * @author Artem Bilan |
| 83 | + */ |
| 84 | +fun integrationFlow(messageSource: MessageSource<*>, |
| 85 | + options: SourcePollingChannelAdapterSpec.() -> Unit = {}, |
| 86 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 87 | + buildIntegrationFlow(IntegrationFlows.from(messageSource, Consumer { options(it) }), flow) |
| 88 | + |
| 89 | +/** |
| 90 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 91 | + * `IntegrationFlows.from(MessageSourceSpec<*>, Consumer<SourcePollingChannelAdapterSpec>)` factory method. |
| 92 | + * |
| 93 | + * @author Artem Bilan |
| 94 | + */ |
| 95 | +fun integrationFlow(messageSource: MessageSourceSpec<*, out MessageSource<*>>, |
| 96 | + options: SourcePollingChannelAdapterSpec.() -> Unit = {}, |
| 97 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 98 | + buildIntegrationFlow(IntegrationFlows.from(messageSource, options), flow) |
| 99 | + |
| 100 | +/** |
| 101 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 102 | + * `IntegrationFlows.from(Supplier<*>, Consumer<SourcePollingChannelAdapterSpec>)` factory method. |
| 103 | + * |
| 104 | + * @author Artem Bilan |
| 105 | + */ |
| 106 | +fun integrationFlow(source: () -> Any, |
| 107 | + options: SourcePollingChannelAdapterSpec.() -> Unit = {}, |
| 108 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 109 | + buildIntegrationFlow(IntegrationFlows.from(source, options), flow) |
| 110 | + |
| 111 | +/** |
| 112 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 113 | + * `IntegrationFlows.from(Publisher<out Message<*>>)` factory method. |
| 114 | + * |
| 115 | + * @author Artem Bilan |
| 116 | + */ |
| 117 | +fun integrationFlow(publisher: Publisher<out Message<*>>, |
| 118 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 119 | + buildIntegrationFlow(IntegrationFlows.from(publisher), flow) |
| 120 | + |
| 121 | +/** |
| 122 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 123 | + * `IntegrationFlows.from(MessagingGatewaySupport)` factory method. |
| 124 | + * |
| 125 | + * @author Artem Bilan |
| 126 | + */ |
| 127 | +fun integrationFlow(gateway: MessagingGatewaySupport, |
| 128 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 129 | + buildIntegrationFlow(IntegrationFlows.from(gateway), flow) |
| 130 | + |
| 131 | +/** |
| 132 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 133 | + * `IntegrationFlows.from(MessagingGatewaySpec<*, *>)` factory method. |
| 134 | + * |
| 135 | + * @author Artem Bilan |
| 136 | + */ |
| 137 | +fun integrationFlow(gatewaySpec: MessagingGatewaySpec<*, *>, |
| 138 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 139 | + buildIntegrationFlow(IntegrationFlows.from(gatewaySpec), flow) |
| 140 | + |
| 141 | +/** |
| 142 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 143 | + * `IntegrationFlows.from(MessageProducerSupport)` factory method. |
| 144 | + * |
| 145 | + * @author Artem Bilan |
| 146 | + */ |
| 147 | +fun integrationFlow(producer: MessageProducerSupport, |
| 148 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 149 | + buildIntegrationFlow(IntegrationFlows.from(producer), flow) |
| 150 | + |
| 151 | +/** |
| 152 | + * Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] - |
| 153 | + * `IntegrationFlows.from(MessageProducerSpec<*, *>)` factory method. |
| 154 | + * |
| 155 | + * @author Artem Bilan |
| 156 | + */ |
| 157 | +fun integrationFlow(producerSpec: MessageProducerSpec<*, *>, |
| 158 | + flow: KotlinIntegrationFlowDefinition.() -> Unit) = |
| 159 | + buildIntegrationFlow(IntegrationFlows.from(producerSpec), flow) |
0 commit comments