A simple implementation of the Dubbo protocol.

Overview

Codec-dubbo

Build codecov Maven Central GitHub license

Codec-dubbo is a binary codec framework for dubbo protocol

Features

  • Fully compatible with Dubbo protocol
  • Completely rewritten based on Netty, does not rely on native Dubbo
  • Support only parsing metadata but not body (suitable for proxy scenarios)
  • Support Dubbo Server
  • Support Dubbo Client
  • Multiple serialization protocols support

SDK instructions

1、Introduce Maven dependencies

<dependency>
    <groupId>io.esastack</groupId>
    <artifactId>codec-dubbo-client</artifactId>
    <version>${mvn.version}</version>
</dependency>
<dependency>
    <groupId>io.esastack</groupId>
    <artifactId>codec-dubbo-server</artifactId>
    <version>${mvn.version}</version>
</dependency>

2、Dubbo Client SDK instructions

public class DubboSDKClient {

   public static void main(String[] args) throws Exception {
       // build client
       final Map<ChannelOption, Object> channelOptions = new HashMap<>();
       channelOptions.put(ChannelOption.SO_KEEPALIVE, true);
       channelOptions.put(ChannelOption.TCP_NODELAY, true);
       channelOptions.put(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000);
       final DubboClientBuilder.MultiplexPoolBuilder multiplexPoolBuilder = DubboClientBuilder.MultiplexPoolBuilder.newBuilder();
       final DubboClientBuilder builder = new DubboClientBuilder()
               .setMultiplexPoolBuilder(multiplexPoolBuilder)
               .setChannelOptions(channelOptions)
               .setHost("localhost")
               .setPort(20880);
       NettyDubboClient nettyDubboClient = new NettyDubboClient(builder);

       // build request
       RpcInvocation rpcInvocation = new RpcInvocation();
       rpcInvocation.setMethodName("sayHello");
       rpcInvocation.setParameterTypes(new Class[]{String.class});
       rpcInvocation.setArguments(new String[]{"dubbo"});
       rpcInvocation.setInterfaceName("org.apache.dubbo.demo.DemoService");
       rpcInvocation.setReturnType(String.class);

       Map<String, String> attachments = new HashMap<>();
       rpcInvocation.setAttachments(attachments);

       DubboMessage request = ClientCodecHelper.toDubboMessage(rpcInvocation);

       // Send the request and handle the return value
       CompletableFuture<RpcResult> responseFuture = nettyDubboClient.sendRequest(request, String.class);

       responseFuture.whenComplete((r, t) -> {
           if (t != null || r.getException() != null || StringUtils.isNotEmpty(r.getErrorMessage())) {
               // handle exception
           }
           // handle return value r.getValue();
       });
   }
}

3、 Dubbo Server SDK instructions

public class DubboSDKServer {

    private static final Logger LOGGER = LoggerFactory.getLogger(DubboSDKServer.class);

    static ExecutorService workerThreadPool =
            ThreadPools.builder()
                    .corePoolSize(200)
                    .maximumPoolSize(200)
                    .useSynchronousQueue()
                    .rejectPolicy((r, executor) -> LOGGER.error("rejectedExecution ")).build();

    public static void main(String[] args) {
        // build server
        DubboServerBuilder dubboServerBuilder = new DubboServerBuilder()
                .setPort(20880)
                .setBizHandler(new DubboServerBizHandler() { // handle request and return response
                    @Override
                    public void process(DubboMessage request, DubboResponseHolder dubboResponseHolder) {
                        final RpcInvocation invocation;
                        try {
                            // parse request
                            invocation = ServerCodecHelper.toRpcInvocation(request);
                        } catch (Exception e) {
                            LOGGER.error("Failed to convert request to rpc invocation for {}", e);
                            dubboResponseHolder.end(null);
                            return;
                        }
                        workerThreadPool.execute(() -> {
                            String response = "requestId:" +
                                    invocation.getRequestId() +
                                    " Hello " + invocation.getArguments()[0] +
                                    ", response from provider. seriType:" +
                                    invocation.getSeriType();

                            DubboMessage dubboResponse = null;
                            try {
                                // build response
                                dubboResponse = ServerCodecHelper.toDubboMessage(
                                        RpcResult.success(
                                                invocation.getRequestId(),
                                                invocation.getSeriType(),
                                                response),
                                        request.getBody().alloc());
                            } catch (SerializationException e) {
                                LOGGER.error("Failed to serialize response for {}", e);
                                dubboResponseHolder.getChannelHandlerContext().channel().close();
                            }
                            // send response
                            dubboResponseHolder.end(dubboResponse);
                        });
                    }

                    @Override
                    public void shutdown() {

                    }
                });
        NettyDubboServer nettyDubboServer = new NettyDubboServer(dubboServerBuilder);

        // start server
        nettyDubboServer.start();
    }
}
You might also like...

Realtime Data Processing and Search Engine Implementation.

Realtime Data Processing and Search Engine Implementation.

Mutad The name Mutad is a reverse spelling of datum. Overview An implementation of a real-time data platform/search engine based on various technology

Aug 4, 2022

A Graphics2D implementation targeting Skija as a backend.

A Graphics2D implementation targeting Skija as a backend.

SkijaGraphics2D Version 1.0.2, 4 August 2021 Overview SkijaGraphics2D is an implementation of Java2D's Graphics2D API that targets Skia via the Skija

Dec 29, 2022

Daily mail subscription implementation using Java Spring-boot and Quartz Scheduler

Daily Mail Subscription Service POC Implemented using Java Spring-boot and Quartz Scheduler Working Application Exposing 3 endpoints /subscription/cre

Jun 3, 2022

A minimal WHIP implementation for the Raspberry Pi. It sends Mic and Camera to a WHIP endpoint

whipi A minimal WHIP implementation for the Raspberry Pi. It sends Camera Mic to a WHIP endpoint. Requires a Raspberry Pi with a PiCam and Java 11. It

Oct 27, 2022

A visual implementation of OSHI, to view information about the system and hardware.

A visual implementation of OSHI, to view information about the system and hardware.

MooInfo A visual implementation of OSHI, to view information about the system and hardware. Such as OS, processes, memory, CPU, disks, devices, sensor

Jan 6, 2023

Sui - Modern super user interface implementation on Android.

Sui Modern super user interface (SUI) implementation on Android. The name, Sui, also comes from a character. Introduction Sui provides Java APIs, Shiz

Jan 5, 2023

Model Layer Implementation for a J2EE Pull MVC WebApp

Model Layer Implementation for a J2EE Pull MVC WebApp

Modality is a lightweight but hightly configurable Java ORM, with a companion set of tools docs home modality-core doc modality-webapp doc velocity-to

Jan 3, 2023

A base implementation for a microservice

RapidPM - Microservice A base implementation for a microservice based on the Undertow. The Core Service will listen on IP 0.0.0.0 The base configurati

Jul 26, 2020

Pure Java implementation of ONCRPC/SUNRPC

ONCRPC4J This is a part of dCache.ORG's NFSv4.1 work. Technically, this is not a fork of Remote Tea RPC library, but formally it is as we was inspired

Oct 27, 2022
Comments
  • Fixed the memory leak problem

    Fixed the memory leak problem

    Fixed the memory leak problem that the byteBuf could not be released when the heartbeat returned packet and the error report and optimize the README.md

    opened by EnigmaOppo 0
Owner
ESA Stack
Elastic Service Architecture
ESA Stack
一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024

友情提示:因为提供了 50000+ 行示例代码,所以艿艿默认注释了所有 Maven Module。 胖友可以根据自己的需要,修改 pom.xml 即可。 一个涵盖六个主流技术栈的正经仓库: 《Spring Boot 专栏》 《Spring Cloud Alibaba 专栏》 《Spring Clou

芋道源码 15.7k Dec 31, 2022
:herb: 基于springboot的快速学习示例,整合自己遇到的开源框架,如:rabbitmq(延迟队列)、Kafka、jpa、redies、oauth2、swagger、jsp、docker、spring-batch、异常处理、日志输出、多模块开发、多环境打包、缓存cache、爬虫、jwt、GraphQL、dubbo、zookeeper和Async等等:pushpin:

欢迎大家留言和PR~ Tip: 技术更新换代太快,本仓库仅做参考,自己的项目具体使用哪个版本还需谨慎思考~(不推荐使用最新的版本,推荐使用(最新-1|2)的版本,会比较稳定) spring-boot-quick 前言   自己很早就想搞一个总的仓库就是将自己平时遇到的和学习到的东西整合在一起,方便后

wangxc 2.1k Jan 2, 2023
A dubbo gateway based Java language.

A dubbo gateway based Java language.

老夫正年轻 19 Sep 24, 2022
Apache/Alibaba Dubbo <= 2.7.3 PoC Code for CVE-2021-25641 RCE via Deserialization of Untrusted Data; Affects Versions <= 2.7.6 With Different Gadgets

The 0xDABB of Doom - CVE-2021-25641-Proof-of-Concept Apache/Alibaba Dubbo <= 2.7.3 PoC Code for CVE-2021-25641 RCE via Deserialization of Untrusted Da

Dor Tumarkin 51 Apr 24, 2022
A lightweight messaging library that simplifies the development and usage of RabbitMQ with the AMQP protocol.

kryo-messaging This library contains a simple MessagingService which simplifies the setup and work with RabbitMQ and the AMQP protocol. Usage Gradle r

Kryonite Labs 3 Jan 10, 2022
A fault tolerant, protocol-agnostic RPC system

Finagle Status This project is used in production at Twitter (and many other organizations), and is being actively developed and maintained. Releases

Twitter 8.5k Jan 4, 2023
UHI is envisioned as an open protocol for various digital health services.

UHI is envisioned as an open protocol for various digital health services. UHI Network will be an open network of End User Applications (EUAs) and participating Health Service Provider (HSP) applications. UHI will enable a wide variety of digital health services between patients and health service providers (HSPs) including appointment booking, teleconsultation, service discovery and others

National Health Authority 59 Dec 21, 2022
SimpleIcons4J is a Java implementation of the simple-icons JavaScript library

SimpleIcons4J SimpleIcons4J is a Java implementation of the simple-icons JavaScript library and is inspired by simpleicons.org. This library currently

Hyesung Lee 3 Apr 9, 2022
This program is a simple machine learning implementation in Java for detecting skin pixels.

Skin Detector ?? ?? Detects human skin from images This program is a simple machine learning implementation in Java for detecting skin pixels. How to

Tasmia Zerin 1 Jan 21, 2022
Simple and extensible storage service implementation with optional encryption.

Simple and extensible storage service implementation with optional encryption. About Hole Hole is a simple data storage made with a soul for those who

d1s utils 3 Aug 13, 2022