Example usage for com.rabbitmq.client RpcServer mainloop

List of usage examples for com.rabbitmq.client RpcServer mainloop

Introduction

In this page you can find the example usage for com.rabbitmq.client RpcServer mainloop.

Prototype

public ShutdownSignalException mainloop() throws IOException 

Source Link

Document

Public API - main server loop.

Usage

From source file:it.jugtorino.one.msvc.way.rabbit.geoip.reference.service.Main.java

License:Open Source License

public static void main(String[] args) throws Exception {
    GeoIPDao geoIPDao = setupDAO(args[0]);
    IPLocation ipLocation = setupIPLocation(geoIPDao);
    Channel channel = setupRabbitMQ();

    RpcServer rpcServer = new RpcServer(channel, "geoip_service_v1") {

        @Override/*from w  ww  .j  a  v  a  2 s. co  m*/
        public byte[] handleCall(byte[] requestBody, AMQP.BasicProperties replyProperties) {
            try {
                Map<String, Object> request = JSONUtils.toMap(requestBody);

                if (request.get("resolve_ip") == null) {
                    return JSONUtils.toBytes(new HashMap<>());
                }
                Map<String, Object> response = handleIPLocationRequest(request, ipLocation);

                System.out.println("REQUEST=" + request);
                System.out.println("RESPONSE=" + response);
                return JSONUtils.toBytes(response);
            } catch (Exception e) {
                Map<String, Object> error = new HashMap<>();
                error.put("message", e.getMessage());
                return JSONUtils.toBytes(error);
            }
        }

    };

    System.out.println("READY");
    rpcServer.mainloop();
}

From source file:it.jugtorino.one.msvc.way.rabbit.geoip.reference.service.MainTemplate.java

License:Open Source License

public static void main(String[] args) throws Exception {
    GeoIPDao geoIPDao = setupDAO(args[0]);
    IPLocation ipLocation = setupIPLocation(geoIPDao);
    Channel channel = setupRabbitMQ();

    RpcServer rpcServer = new RpcServer(channel, "geoip_service_v1") {

        @Override/*from   www  .j  ava 2  s .co  m*/
        public byte[] handleCall(byte[] requestBody, AMQP.BasicProperties replyProperties) {
            return super.handleCall(requestBody, replyProperties);
        }

    };

    System.out.println("READY");
    rpcServer.mainloop();
}