最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring boot udp或者tcp接收數(shù)據(jù)的實例詳解

 更新時間:2021年12月01日 09:49:04   作者:JakeWin  
這篇文章主要介紹了spring boot udp或者tcp接收數(shù)據(jù),本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

下面用的是 springboot內(nèi)置integration依賴

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-ip</artifactId>
        </dependency>

下面是一個類 用來接收udp協(xié)議和tcp協(xié)議的數(shù)據(jù)

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.Filter;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter;
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
import org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer;
import org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter;
import org.springframework.messaging.Message;

@Configuration
public class DataReceiveConfigration {

    
    @Bean
    public UnicastReceivingChannelAdapter getUnicastReceivingChannelAdapter() {
        UnicastReceivingChannelAdapter adapter = new  UnicastReceivingChannelAdapter(4567);//實例化一個udp 4567端口
        adapter.setOutputChannelName("udp");
        return adapter;
    }
    
    @Transformer(inputChannel="udp",outputChannel="udpString")
    public String transformer(Message<?> message) {
        return new String((byte[])message.getPayload());//把接收的數(shù)據(jù)轉(zhuǎn)化為字符串
    }
    
    @Filter(inputChannel="udpString",outputChannel="udpFilter")
    public boolean filter(String message) {
        return message.startsWith("abc");//如果接收數(shù)據(jù)開頭不是abc直接過濾掉
    }

   @Router(inputChannel="udpFilter")
    public String routing(String message) {
        if(message.contains("1")) {//當(dāng)接收數(shù)據(jù)包含數(shù)字1時
            return "udpRoute1";
        }
        else {
            return "udpRoute2";
        }    
    }

    
   @ServiceActivator(inputChannel="udpRoute1")
   public void udpMessageHandle(String message) {
       System.out.println("udp1:" +message);
   }

    @ServiceActivator(inputChannel="udpRoute2")
    public void udpMessageHandle2(String message) {
        System.out.println("udp2:" +message);
    }
    
    @Bean
    public TcpNetServerConnectionFactory getServerConnectionFactory() {
        TcpNetServerConnectionFactory serverConnectionFactory = new TcpNetServerConnectionFactory(1234);
        serverConnectionFactory.setSerializer(new ByteArrayRawSerializer());
        serverConnectionFactory.setDeserializer(new ByteArrayRawSerializer());
        serverConnectionFactory.setLookupHost(false);
        return serverConnectionFactory;
    }

    @Bean
    public TcpReceivingChannelAdapter getReceivingChannelAdapter() {
        TcpReceivingChannelAdapter receivingChannelAdapter = new TcpReceivingChannelAdapter();
        receivingChannelAdapter.setConnectionFactory(getServerConnectionFactory());
        receivingChannelAdapter.setOutputChannelName("tcp");
        return receivingChannelAdapter;
    }

    @ServiceActivator(inputChannel="tcp")
    public void messageHandle(Message<?> message) {
        System.out.println(new String((byte[])message.getPayload()));
    }
}

到此這篇關(guān)于spring boot udp或者tcp接收數(shù)據(jù)的實例詳解的文章就介紹到這了,更多相關(guān)spring boot接收數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • SpringBoot2.x漏洞將logback1.2.x 升級至1.3.x

    SpringBoot2.x漏洞將logback1.2.x 升級至1.3.x

    安全部門在代碼漏洞掃描中發(fā)現(xiàn)logback 1.2.x版本存在CVE漏洞,建議升級至1.3.x版本,本文就來介紹了logback1.2.x 升級至1.3.x,具有一定的參考價值,感興趣的可以了解一下
    2024-09-09
  • 阿里云部署SpringBoot項目啟動后被殺進程的問題解析

    阿里云部署SpringBoot項目啟動后被殺進程的問題解析

    這篇文章主要介紹了阿里云部署SpringBoot項目啟動后被殺進程的問題,本文給大家分享問題原因所在及解決步驟,需要的朋友可以參考下
    2023-09-09
  • Spring Validation方法實現(xiàn)原理分析

    Spring Validation方法實現(xiàn)原理分析

    這篇文章主要介紹了Spring Validation實現(xiàn)原理分析,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • python 與HFSS聯(lián)合仿真的教程講解

    python 與HFSS聯(lián)合仿真的教程講解

    這篇文章主要介紹了python 與HFSS聯(lián)合仿真的教程講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Spring ApplicationListener監(jiān)聽器用法詳解

    Spring ApplicationListener監(jiān)聽器用法詳解

    這篇文章主要介紹了Spring ApplicationListener監(jiān)聽器用法詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-11-11
  • java實現(xiàn)雙層圣誕樹加修飾代碼示例

    java實現(xiàn)雙層圣誕樹加修飾代碼示例

    大家好,本篇文章主要講的是java實現(xiàn)雙層圣誕樹加修飾代碼示例,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • Intellij?IDEA?中調(diào)試?maven?插件的步驟

    Intellij?IDEA?中調(diào)試?maven?插件的步驟

    這篇文章主要介紹了Intellij?IDEA?中調(diào)試?maven?插件,本文分步驟給大家講解的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03
  • Java基于Rest?Assured自動化測試接口詳解

    Java基于Rest?Assured自動化測試接口詳解

    Rest Assured 是一個基于 Java 的流行的用于測試 RESTful API 的庫。這篇文章主要介紹了Java如何基于Rest?Assured實現(xiàn)自動化測試接口,需要的可以參考一下
    2023-03-03
  • SpringBoot中自定義注解實現(xiàn)控制器訪問次數(shù)限制實例

    SpringBoot中自定義注解實現(xiàn)控制器訪問次數(shù)限制實例

    本篇文章主要介紹了SpringBoot中自定義注解實現(xiàn)控制器訪問次數(shù)限制實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-04-04
  • 使用concurrentHashMap如何實現(xiàn)緩存

    使用concurrentHashMap如何實現(xiàn)緩存

    文章介紹了使用ConcurrentHashMap實現(xiàn)緩存的線程安全性和初始化方法,以及如何處理高并發(fā)場景下的緩存清理和數(shù)據(jù)一致性問題,包括分桶、使用ConcurrentLinkedQueue以及使用CountDownLatch來確保緩存數(shù)據(jù)的不丟失
    2025-02-02

最新評論

宜宾县| 苍溪县| 茶陵县| 兴城市| 青海省| 洪湖市| 增城市| 华亭县| 丽水市| 开江县| 怀柔区| 溆浦县| 东乡族自治县| 溧水县| 壶关县| 阳新县| 西乌珠穆沁旗| 宿松县| 梁平县| 汾西县| 长岭县| 谢通门县| 巢湖市| 子长县| 辽阳县| 华容县| 古丈县| 抚顺市| 浑源县| 宝清县| 古蔺县| 台州市| 龙江县| 田林县| 桂林市| 南雄市| 嘉义县| 葵青区| 城口县| 克什克腾旗| 田林县|