Skip to content

DSL synchronous UDP multicast #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,32 @@ project('kafka-dsl') {
}
}

project('synchronous-udp-multicast') {
description = 'Java DSL synchronous UDP multicast'

apply plugin: 'org.springframework.boot'

dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-integration'
compile 'org.springframework.integration:spring-integration-ip'
compile 'org.springframework.integration:spring-integration-http'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
bootRun {
main = 'org.springframework.integration.samples.dsl.synchronous.multicast.Application'
}

task run(type: JavaExec) {
main 'org.springframework.integration.samples.dsl.synchronous.multicast.Application'
classpath = sourceSets.main.runtimeClasspath
}

tasks.withType(JavaExec) {
standardInput = System.in
}
}

project('file-split-ftp') {
description = 'File Split FTP'

Expand Down
25 changes: 25 additions & 0 deletions dsl/synchronous-udp-multicast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Spring Integration Java DSL synchronous UDP multicast
==============

This example demonstrates the use of `Http Inbound Components`, `Http Outbound Components`, `UDP Adapters` and `IntegrationFlowContext` class to create a UDP multicast synchronous gateway.

## Flow

The idea is to send a UDP multicast message in an synchronous way, so, it waits until a response arrieves from any of the UDP nodes joined to the multicast group.

Client Server

udpMulticastOutbound -->> udpMulticastInbound
|
|
v
v
httpInbound <<-- httpOutbound



## Running the sample

Run the test example.

$ gradlew :synchronous-udp-multicast:test
134 changes: 134 additions & 0 deletions dsl/synchronous-udp-multicast/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>synchronous-udp-multicast</artifactId>
<version>5.0.0.BUILD-SNAPSHOT</version>
<name>Java DSL synchronous UDP multicast</name>
<description>Java DSL synchronous UDP multicast</description>
<url>http://projects.spring.io/spring-integration</url>
<organization>
<name>SpringIO</name>
<url>https://spring.io</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>estigma88</id>
<name>Daniel Andres Pelaez Lopez</name>
<email>[email protected]</email>
<roles>
<role>project lead</role>
</roles>
</developer>
</developers>
<scm>
<connection>scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git</connection>
<developerConnection>scm:git:scm:git:ssh://[email protected]:spring-projects/spring-integration-samples.git</developerConnection>
<url>https://github.com/spring-projects/spring-integration-samples</url>
</scm>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jackson-module-kotlin</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ip</artifactId>
<version>5.0.4.RELEASE</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jackson-module-kotlin</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-http</artifactId>
<version>5.0.4.RELEASE</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jackson-module-kotlin</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>jackson-module-kotlin</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.spring.io.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>https://repo.spring.io/libs-milestone</url>
</repository>
<repository>
<id>repo.spring.io.snapshot</id>
<name>Spring Framework Maven Snapshot Repository</name>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.2.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>5.0.5.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>5.0.5.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2016-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.samples.dsl.synchronous.multicast;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.dsl.context.IntegrationFlowContext;
import org.springframework.integration.samples.dsl.synchronous.multicast.starter.SynchronousUDPStarter;

/**
* @author Daniel Andres Pelaez Lopez
*/
@SpringBootApplication
public class Application {

public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}

@Bean
public SynchronousUDPStarter synchronousUDPStarter(IntegrationFlowContext flowContext,
@Value("${synchronous.multicast.group}") String group,
@Value("${synchronous.multicast.port}") Integer port) {
SynchronousUDPStarter synchronousUDPStarter = new SynchronousUDPStarter(flowContext, group, port);

synchronousUDPStarter.init();

return synchronousUDPStarter;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.samples.dsl.synchronous.multicast.gateway;

/**
* @author Daniel Andres Pelaez Lopez
*/
public interface UDPMulticastGateway {
String send(String request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.samples.dsl.synchronous.multicast.handler;

/**
* @author Daniel Andres Pelaez Lopez
*/
public class UDPMulticastHandler {
public String handle(String request) {
return "Response for '" + request + "'";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.samples.dsl.synchronous.multicast.starter;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* @author Daniel Andres Pelaez Lopez
*/
public class ExtendedMessage {
private final String replyOriginChannelId;
private final String errorOriginChannelId;
private final String data;

@JsonCreator
ExtendedMessage(@JsonProperty("replyOriginChannelId") String replyOriginChannelId,
@JsonProperty("errorOriginChannelId") String errorOriginChannelId,
@JsonProperty("data") String data) {
this.replyOriginChannelId = replyOriginChannelId;
this.errorOriginChannelId = errorOriginChannelId;
this.data = data;
}

public String getReplyOriginChannelId() {
return replyOriginChannelId;
}

public String getErrorOriginChannelId() {
return errorOriginChannelId;
}

public String getData() {
return data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.samples.dsl.synchronous.multicast.starter;

import org.springframework.integration.transformer.Transformer;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;

/**
* @author Daniel Andres Pelaez Lopez
*/
public class ExtendedMessageTransformer implements Transformer {
@Override
public Message<?> transform(Message<?> message) {
return MessageBuilder
.withPayload(new ExtendedMessage((String) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL),
(String) message.getHeaders().get(MessageHeaders.ERROR_CHANNEL),
(String) message.getPayload()))
.copyHeaders(message.getHeaders())
.build();
}
}
Loading