public void server() {
        ConnectionFactory factory = new ConnectionFactory();
        Connection connection = null;
        try {
            connection = factory.newConnection();
            Channel channel = connection.createChannel();

            channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
            channel.basicQos(1);

            QueueingConsumer consumer = new QueueingConsumer(channel);
            channel.basicConsume(RPC_QUEUE_NAME, false, consumer); // explicit ack

            System.out.println("RPC Fibonacci calculator is ready");

            boolean terminator = false;
            while (true) {
                String response = "";

                QueueingConsumer.Delivery delivery = consumer.nextDelivery();

                try {
                    String message = new String(delivery.getBody());
                    if(message.isEmpty()) {
                        System.out.println("Empty message, terminating");
                        terminator = true;
                        break;
                    }

                    int n = Integer.parseInt(message);
                    System.out.println("Calculating fibonacci(" + message + ")");
                    if(n < MIN_INPUT || n > MAX_INPUT)
                        response = "N/A";
                    else
                        response += fibonacci(n);
                }
                catch (Exception e){
                    e.printStackTrace();
                }
                finally {
                    if(!terminator) {
                        BasicProperties bp = delivery.getProperties();
                        String corrId = bp.getCorrelationId();
                        String replyQueue = bp.getReplyTo();
                        System.out.println("Replying to " + replyQueue + ", " + corrId);
                        
                        BasicProperties replyProps = new BasicProperties.Builder().correlationId(corrId).build();
                        channel.basicPublish("", replyQueue, replyProps, response.getBytes());
                    }
                    channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
                }
            }
        }
        catch  (Exception e) {
            e.printStackTrace();
        }
        finally {
            try{ if(connection != null) connection.close(); } catch(IOException e) {}
        }
    }