public class

RpcServer

extends Object
java.lang.Object
   ↳ com.rabbitmq.client.RpcServer
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Class which manages a request queue for a simple RPC-style service. The class is agnostic about the format of RPC arguments / return values.

Summary

Public Constructors
RpcServer(Channel channel)
Creates an RpcServer listening on a temporary exclusive autodelete queue.
RpcServer(Channel channel, String queueName)
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.
Public Methods
void close()
Public API - cancels the consumer, thus deleting the queue, if it was a temporary queue, and marks the RpcServer as closed.
Channel getChannel()
Retrieve the channel.
String getQueueName()
Retrieve the queue name.
byte[] handleCall(QueueingConsumer.Delivery request, AMQP.BasicProperties replyProperties)
Lowest-level response method.
byte[] handleCall(AMQP.BasicProperties requestProperties, byte[] requestBody, AMQP.BasicProperties replyProperties)
Mid-level response method.
byte[] handleCall(byte[] requestBody, AMQP.BasicProperties replyProperties)
High-level response method.
void handleCast(AMQP.BasicProperties requestProperties, byte[] requestBody)
Mid-level handler method.
void handleCast(byte[] requestBody)
High-level handler method.
void handleCast(QueueingConsumer.Delivery request)
Lowest-level handler method.
ShutdownSignalException mainloop()
Public API - main server loop.
void processRequest(QueueingConsumer.Delivery request)
Private API - Process a single request.
void terminateMainloop()
Call this method to terminate the mainloop.
Protected Methods
QueueingConsumer setupConsumer()
Registers a consumer on the reply queue.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public RpcServer (Channel channel)

Creates an RpcServer listening on a temporary exclusive autodelete queue.

Throws
IOException

public RpcServer (Channel channel, String queueName)

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.

Throws
IOException

Public Methods

public void close ()

Public API - cancels the consumer, thus deleting the queue, if it was a temporary queue, and marks the RpcServer as closed.

Throws
IOException if an error is encountered

public Channel getChannel ()

Retrieve the channel.

Returns
  • the channel to which this server is connected

public String getQueueName ()

Retrieve the queue name.

Returns
  • the queue which this server is consuming from

public byte[] handleCall (QueueingConsumer.Delivery request, AMQP.BasicProperties replyProperties)

Lowest-level response method. Calls handleCall(AMQP.BasicProperties,byte[],AMQP.BasicProperties).

public byte[] handleCall (AMQP.BasicProperties requestProperties, byte[] requestBody, AMQP.BasicProperties replyProperties)

Mid-level response method. Calls handleCall(byte[],AMQP.BasicProperties).

public byte[] handleCall (byte[] requestBody, AMQP.BasicProperties replyProperties)

High-level response method. Returns an empty response by default - override this (or other handleCall and handleCast methods) in subclasses.

public void handleCast (AMQP.BasicProperties requestProperties, byte[] requestBody)

Mid-level handler method. Calls handleCast(byte[]).

public void handleCast (byte[] requestBody)

High-level handler method. Does nothing by default - override this (or other handleCast and handleCast methods) in subclasses.

public void handleCast (QueueingConsumer.Delivery request)

Lowest-level handler method. Calls handleCast(AMQP.BasicProperties,byte[]).

public ShutdownSignalException mainloop ()

Public API - main server loop. Call this to begin processing requests. Request processing will continue until the Channel (or its underlying Connection) is shut down, or until terminateMainloop() is called. Note that if the mainloop is blocked waiting for a request, the termination flag is not checked until a request is received, so a good time to call terminateMainloop() is during a request handler.

Returns
  • the exception that signalled the Channel shutdown, or null for orderly shutdown
Throws
IOException

public void processRequest (QueueingConsumer.Delivery request)

Private API - Process a single request. Called from mainloop().

Throws
IOException

public void terminateMainloop ()

Call this method to terminate the mainloop. Note that if the mainloop is blocked waiting for a request, the termination flag is not checked until a request is received, so a good time to call terminateMainloop() is during a request handler.

Protected Methods

protected QueueingConsumer setupConsumer ()

Registers a consumer on the reply queue.

Returns
  • the newly created and registered consumer
Throws
IOException if an error is encountered