日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【dubbo】消费者Consumer搭建

發布時間:2023/12/10 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【dubbo】消费者Consumer搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一.consumer搭建(可以web/jar)

1.新建Maven項目,groupId:com.dubbo.consumer.demo artifactId:demo projectName:dubboo-consumer-demo

2.新建class :com.dubbo.consumer.demo.DemoAction

package com.dubbo.consumer.demo;import java.text.SimpleDateFormat; import java.util.Date; import com.dubbo.api.demo.*; /*** Created by Administrator on 17-1-7.*/ public class DemoAction {private static DemoService demoService;public void setDemoService(DemoService demoService) {this.demoService = demoService;}public void start() throws Exception {for (int i = 0; i < Integer.MAX_VALUE; i ++) {try {String hello = demoService.sayHello("world" + i);System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + hello);} catch (Exception e) {e.printStackTrace();}Thread.sleep(2000);}} }

3.添加配置文件spring-dubbo-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://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"><dubbo:application name="dubbo-consumer-demo" ></dubbo:application><dubbo:registry address="zookeeper://127.0.0.1:2181" protocol="zookeeper"></dubbo:registry><dubbo:reference id="demoService" interface="com.dubbo.api.demo.DemoService" ></dubbo:reference></beans>

4.修改maven配置文件pom.xml,添加spring、dubbo、dubbo-api

<dependencies><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.4.10</version></dependency><dependency><groupId>com.github.sgroschupf</groupId><artifactId>zkclient</artifactId><version>0.1</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>3.2.16.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>3.2.16.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>3.2.16.RELEASE</version></dependency><dependency><groupId>com.dubbo.api.demo</groupId><artifactId>dubbo-interface</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies>

?5.添加消費者Class DemoConsumer

package Consumer;/** Copyright 1999-2011 Alibaba Group.* * 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.*/import com.dubbo.api.demo.*; import org.springframework.context.support.ClassPathXmlApplicationContext;public class DemoConsumer {public static void main(String[] args) {ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("META-INFO/spring-dubbo-consumer.xml");ctx.start();DemoService demoService = (DemoService) ctx.getBean("demoService");String hello = demoService.sayHello("world" + 1);System.out.println("[" + hello);ctx.close();}}

?

?二、總結

1.web或jar包形式發布消費者都可以

2.工程中涉及主要配置

? A.consumer.xml 中引入API(interface)

? B.pom.xml中引入API(Interface)jar包

? C.接口實現在provider中完成,本地引入接口定義jar即可

? D.java中import api package

轉載于:https://www.cnblogs.com/grape1211/p/6259270.html

總結

以上是生活随笔為你收集整理的【dubbo】消费者Consumer搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。