Spring-Cloud-stream-rabbit导致Netty无法启动

发布于 2025-01-24 09:07:20 字数 3425 浏览 1 评论 0原文

他们不能一起工作吗? 实际上,端口没有被占据。使用Netty TCP连接端口58888(或更改为任何其他端口)IT(Netty)不起作用。当我不使用SpringCloudstream时,Netty可以正常启动。

Netty启动错误: “ java.net.bindexception:已在使用中的地址:绑定”

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.6.7</version>
  </dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
    <version>3.2.2</version>
</dependency>

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.75.Final</version>
</dependency>

​----------------- config ---------------------------------------------------------------- - -

  rabbitmq:
    host: 192.168.31.248
    port: 5672
    username: rabbit
    password: 123456
    virtual-host: /
  cloud:
    stream:
      bindings:
        sms-out-0:
          destination: sms-exchange

- - - - - - - - - - - - - - - - - 消费者 - - - - - - --------------------------------------------------------------------------------

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.function.Consumer;

@Component
public class SmsConsumer {
    
    @Bean
    public Consumer<String> sms() {
        return System.out::println;
    }
}

​ ---------------------------------------------------------------------------------------------------------------------------------------------------------------]

import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Component
public class SmsProducer{
    
    @Resource
    private StreamBridge streamBridge;
    
    public void send(String message) {
        streamBridge.send("sms-out-0" , message);
    }
}

-生产者 为什么没有结果

...........

当我删除消费者时,Netty正常开始。看来这个问题与港口无关,我仍然不明白原因。

导入org.springframework.stereotype.component;

@Component
public class SmsConsumer {
    
//    @Bean
//    public Consumer<String> sms() {
//        return System.out::println;
//    }
}

当我注意到官方文档有避免混乱的技巧时,会进行以下更改

  rabbitmq:
    host: 192.168.31.248
    port: 5672
    username: rabbit
    password: 123456
    virtual-host: /
  cloud:
    function:
      definition: sms
    stream:
      function:
        autodetect: false
      bindings:
        sms-out-0:
          destination: sms-exchange

spring cloud cloud stream官方文档官方文档具有提示避免混淆

,但问题仍然存在,我无法解决

netty startup错误映像

They can't work together,way ?
In fact, the port is not occupied.Using Netty tcp to connect port 58888 (or change to any other port) it (Netty) is not working. When I don't use SpringCloudStream, netty can start normally.

netty startup error :
"java.net.BindException: Address already in use: bind"

--------------------------------Part Maven-----------------------------------

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.6.7</version>
  </dependency>

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
    <version>3.2.2</version>
</dependency>

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.75.Final</version>
</dependency>

--------------------------------Config-----------------------------------

  rabbitmq:
    host: 192.168.31.248
    port: 5672
    username: rabbit
    password: 123456
    virtual-host: /
  cloud:
    stream:
      bindings:
        sms-out-0:
          destination: sms-exchange

--------------------------------Consumer-----------------------------------

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.function.Consumer;

@Component
public class SmsConsumer {
    
    @Bean
    public Consumer<String> sms() {
        return System.out::println;
    }
}

--------------------------------Producer-----------------------------------

import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Component
public class SmsProducer{
    
    @Resource
    private StreamBridge streamBridge;
    
    public void send(String message) {
        streamBridge.send("sms-out-0" , message);
    }
}

Why is no one having this problem, I don't understand why there are no results..............

-----The follow-up is coming, with new progress!!!!!!!!!!!!!

When I removed the Consumer, Netty started normally. It seems that this problem has nothing to do with the port, and I still don't understand the reason.

import org.springframework.stereotype.Component;

@Component
public class SmsConsumer {
    
//    @Bean
//    public Consumer<String> sms() {
//        return System.out::println;
//    }
}

When I noticed that the official documentation has tips to avoid confusion made the following changes

  rabbitmq:
    host: 192.168.31.248
    port: 5672
    username: rabbit
    password: 123456
    virtual-host: /
  cloud:
    function:
      definition: sms
    stream:
      function:
        autodetect: false
      bindings:
        sms-out-0:
          destination: sms-exchange

Spring Cloud Stream official documentation has tips to avoid confusion

But the problem persists and I can't solve it

netty startup error images

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文