Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An introduction to the course Management dubbo of Advanced docker (14)

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Original articles, welcome to reprint. Reprint please indicate: reproduced from IT Story Association, thank you!

Original link address: "Advanced" docker course Management dubbo introductory drill (14)

Next we are going to talk about course management, and the course service is implemented based on dubbo, so let's warm up, dubbo, and explain to the old buddies who are not familiar with dubbo. Source code: https://github.com/limingios/dubbo.git

Dubbo introduction official website http://dubbo.apache.org/zh-cn/

High performance java-based, RPC framework. Dubbo is an open source project of Alibaba, just like most RPC frameworks, the idea of dubbo revolves around a service, specifying the parameters and return values of a method, this method can be called remotely, on the server side, it will implement this interface, and the service running dubbo will be used to handle client calls. On the client side, there will be a stub that provides a way to connect with the server. In fact, these concepts use the terminology of java: the first step is to define an interface, which is common between the server and the client, the server will complete the implementation of the interface, and the client will call the server through the description of the interface.

Quick start to explain the spring version, according to the official website to create

Create three api,provider,consumer three projects

Local calls are used.

Provider.xml

Consumer.xml

Dubbo-demo com.idig8 1.0-SNAPSHOT 4.0.0 dubbo-demo-consumer com.idig8 dubbo-demo-api 1.0-SNAPSHOT com.alibaba dubbo 2.6.4 org.springframework spring- Context 4.3.0.RELEASE Quick start introduction to springboot version of SpringBoot Integration dubbo example 1, Define API (API module) 1. Define apipackage com.idig8.springboot.dubbo.demo;public interface DemoService {String sayHello (String name);} 2. Install to local

The maven coordinates provided are as follows:

Com.idig8 dubbo-demo-api 1.0-SNAPSHOT II, service provider (provider module) 1. Increase maven dependency org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE io.dubbo.springboot spring-boot-starter-dubbo 1.0.0 com.idig8 dubbo-demo-api 1.0-SNAPSHOT2. Implement the API interface package com.idig8.springboot.dubbo.demo.provider;import com.alibaba.dubbo.config.annotation.Service;import com.idig8.springboot.dubbo.demo.DemoService;@Servicepublic class DemoServiceImpl implements DemoService {public String sayHello (String name) {return "Hello," + name + "(from Spring Boot)" }} 3. Springboot configuration file-application.propertiesspring.dubbo.application.name=demo-provider# here uses broadcast registration. # if there is a Can't assign address exception, you need to add the vm parameter: #-Djava.net.preferIPv4Stack=truespring.dubbo.registry.address=multicast://224.5.6.7:1234spring.dubbo.protocol.name=dubbospring.dubbo.protocol.port=20880spring.dubbo.scan=com.idig8.springboot.dubbo.demo.provider4. Launch class package com.idig8.springboot.dubbo.demo.provider;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class MainProvider {public static void main (String [] args) {SpringApplication.run (MainProvider.class,args);}} III. Service consumer (consumer module) 1. Increase maven dependency org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE org.springframework.boot spring-boot-starter-web io.dubbo.springboot spring-boot-starter-dubbo 1.0.0 com.idig8 dubbo-demo-api 1.0-SNAPSHOT2. Implement controllerpackage com.idig8.springboot.dubbo.demo.consumer;import com.alibaba.dubbo.config.annotation.Reference;import com.idig8.springboot.dubbo.demo.DemoService;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class DemoConsumerController {@ Reference private DemoService demoService; @ RequestMapping ("/ sayHello") public String sayHello (@ RequestParam String name) {return demoService.sayHello (name) }} 3. Springboot configuration file-application.propertiesserver.port=8080#dubbo configspring.dubbo.application.name=demo-consumer# here uses broadcast registration. # if there is a Can't assign address exception, you need to add the vm parameter: #-Djava.net.preferIPv4Stack=truespring.dubbo.registry.address=multicast://224.5.6.7:1234spring.dubbo.scan=com.idig8.springboot.dubbo.demo.consumer4. Launch class package com.idig8.springboot.dubbo.demo.consumer;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Main {public static void main (String [] args) {SpringApplication.run (Main.class,args);}}

The introduction to PS:dubbo ends here, from the integration of spring and springboot to dubbo.

The basic process also said that api establishes the interface, provider implements the interface, and consumer invokes the interface.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report