dubbo 点对点消费端

本文介绍了如何在Java项目中配置Dubbo消费者端,通过排除slf4j依赖,引入dubbo和服务端项目的指定版本。并展示了Consumer类的调用示例以及consumer.xml配置文件内容,强调了点对点消费方式和版本匹配的重要性。
摘要由CSDN通过智能技术生成

pom 中尽量排除 slf4j

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.3.6</version>
    </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.6.6</version>
        </dependency>
        <dependency>
            <groupId>服务端项目组</groupId>
        <artifactId>服务端项目名</artifactId>
        <version>版本</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
        </dependency>

public class Consumer {
    
    public static void main(String[] args) throws Exception {
           ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
            context.start();
            ProviderService providerService =(ProviderService)context.getBean("providerService");
            String hello = providerService.SayHello("hello");
            System.out.println( hello ); // 显示调用结果
        }
}
 

consumer.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd        http://dubbo.apache.org/schema/dubbo        http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
 
    <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
    <dubbo:application name="consumer" owner="sihai"/>
     <!--点对点的方式-->
    <dubbo:registry address="N/A" />
    <dubbo:protocol name="dubbo" port="8005" />

 
    <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
    <dubbo:reference id="providerService" version="1.0.0"
    interface="com.www.service.ProviderService"
    url="dubbo://127.0.0.1:8005/com.www.service.ProviderService" />
</beans>

注意版本号不然会找不到报错

Caused by: com.alibaba.dubbo.remoting.RemotingException: com.alibaba.dubbo.remoting.RemotingException: Not found exported service xxxx

may be version or group mismatch

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值