Example usage for com.rabbitmq.client RpcServer RpcServer

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

Introduction

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

Prototype

public RpcServer(Channel channel, String queueName) throws IOException 

Source Link

Document

If the passed-in queue name is null, creates a server-named temporary exclusive autodelete queue to use; otherwise expects the queue to have already been declared.

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/* www  .  j  av a2s.c o 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  w  ww  .ja  va  2s. c  om*/
        public byte[] handleCall(byte[] requestBody, AMQP.BasicProperties replyProperties) {
            return super.handleCall(requestBody, replyProperties);
        }

    };

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