|
| 1 | +/* |
| 2 | + * Copyright 2019 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.rsocket.inbound; |
| 18 | + |
| 19 | +import java.util.Arrays; |
| 20 | + |
| 21 | +import org.springframework.integration.gateway.MessagingGatewaySupport; |
| 22 | +import org.springframework.messaging.Message; |
| 23 | +import org.springframework.messaging.MessageDeliveryException; |
| 24 | +import org.springframework.messaging.ReactiveMessageHandler; |
| 25 | +import org.springframework.util.Assert; |
| 26 | + |
| 27 | +import reactor.core.publisher.Mono; |
| 28 | + |
| 29 | +/** |
| 30 | + * |
| 31 | + * @author Artem Bilan |
| 32 | + * |
| 33 | + * @since 5.2 |
| 34 | + */ |
| 35 | +public class RSocketInboundGateway extends MessagingGatewaySupport implements ReactiveMessageHandler { |
| 36 | + |
| 37 | + private final String[] path; |
| 38 | + |
| 39 | + public RSocketInboundGateway(String... path) { |
| 40 | + Assert.notNull(path, "'path' must not be null"); |
| 41 | + this.path = path; |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + @Override |
| 46 | + public Mono<Void> handleMessage(Message<?> message) { |
| 47 | + if (!isRunning()) { |
| 48 | + return Mono.error(new MessageDeliveryException(message, |
| 49 | + "The RSocket Inbound Gateway '" + getComponentName() + "' is stopped; " + |
| 50 | + "service for path " + Arrays.toString(this.path) + " is not available at the moment.")); |
| 51 | + } |
| 52 | + return null; |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments