Skip to content

Latest commit

 

History

History
127 lines (104 loc) · 3.95 KB

README.md

File metadata and controls

127 lines (104 loc) · 3.95 KB

Netty Remoting

Codacy Badge Jdk Version License Maven Central

netty-remoting

<dependency>
    <groupId>link.thingscloud</groupId>
    <artifactId>netty-remoting-impl</artifactId>
    <version>${netty-remoting.version}</version>
</dependency>

netty-remoting-spring-boot-starter

<dependency>
    <groupId>link.thingscloud</groupId>
    <artifactId>netty-remoting-spring-boot-starter</artifactId>
    <version>${netty-remoting.version}</version>
</dependency>
# RemotingServerProperties or RemotingClientProperties
netty.remoting.server.serverListenPort=9888
server.shutdown=graceful
@EnableRemotingClientAutoConfiguration
@EnableRemotingServerAutoConfiguration
@SpringBootApplication
public class Bootstrap {

    public static void main(String[] args) {
        SpringApplication.run(Bootstrap.class, args);
    }

    @Autowired
    RemotingClient remotingClient;
    @Autowired
    RemotingServer remotingServer;
    @Autowired
    RemotingCommandFactory factory;

    @PostConstruct
    public void start() {
        RemotingCommand request = factory.createRequest();
        request.cmdCode((short) 13);
        remotingClient.invokeOneWay("127.0.0.1:9888", request);
    }

    @RemotingRequestProcessor(code = 12, type = RemotingType.CLIENT)
    class RequestProcessorImpl1 implements RequestProcessor {
        @Override
        public RemotingCommand processRequest(RemotingChannel channel, RemotingCommand request) {
            System.out.println(request);
            return null;
        }
    }

    @RemotingRequestProcessor(code = 13, type = RemotingType.SERVER)
    class RequestProcessorImpl2 implements RequestProcessor {
        @Override
        public RemotingCommand processRequest(RemotingChannel channel, RemotingCommand request) {
            System.out.println(request);
            return null;
        }
    }

    @RemotingRequestProcessor(code = 14)
    class RequestProcessorImpl3 implements RequestProcessor {
        @Override
        public RemotingCommand processRequest(RemotingChannel channel, RemotingCommand request) {
            System.out.println(request);
            return null;
        }
    }

    @RemotingInterceptor
    class InterceptorImpl implements Interceptor {

        @Override
        public void beforeRequest(RequestContext context) {
            System.out.println(context);
        }

        @Override
        public void afterResponseReceived(ResponseContext context) {
            System.out.println(context);
        }
    }

    @RemotingChannelEventListener
    class ChannelEventListenerImpl implements ChannelEventListener {

        @Override
        public void onChannelConnect(RemotingChannel channel) {
            System.out.println("onChannelConnect");
        }

        @Override
        public void onChannelClose(RemotingChannel channel) {
            System.out.println("onChannelClose");
        }

        @Override
        public void onChannelException(RemotingChannel channel, Throwable cause) {
            System.out.println("onChannelException");
        }

        @Override
        public void onChannelIdle(RemotingChannel channel) {
            System.out.println("onChannelIdle");
        }
    }
}

License

Apache License, Version 2.0 Copyright (C) Apache Software Foundation