com.supermap.messagequeue

Class AMQPManager



  • public class AMQPManager
    extends InternalHandle
    AMQP manager class. Message bus client scheme based on AMQP protocol

    Used to create and bind the queue, switch, receive and send. Through binding queue and switch, and set the unique routingkey to realize the message receiving and sending.

    Please note that, the receiver needs to receive the messages in the sub-thread. And the receive messages is blocking.

    • Constructor Summary

      Constructors 
      Constructor and Description
      AMQPManager()
      The constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean bindQueue(java.lang.String exchange, java.lang.String queue, java.lang.String bindingKey)
      Bind the queue and switch through the specified routingkey
      boolean connection(java.lang.String ip, int port, java.lang.String hostName, java.lang.String usrName, java.lang.String password, java.lang.String clientID)
      Builds connection
      boolean declareExchange(java.lang.String name, AMQPExchangeType exchangeType)
      Declares the switch
      boolean declareQueue(java.lang.String queueName)
      Declare the queue
      boolean deleteExchange(java.lang.String name)
      Delete the switch
      boolean deleteQueue(java.lang.String queueName)
      Delete the queue
      void disconnection()
      Disconnect
      AMQPReceiver newReceiver(java.lang.String queueName)
      Creates a receiver
      AMQPSender newSender()
      Creates a sender
      boolean unbindQueue(java.lang.String queue, java.lang.String exchange, java.lang.String bindingKey)
      Remove the binding between queue and switch
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AMQPManager

        public AMQPManager()
        The constructor.
    • Method Detail

      • connection

        public boolean connection(java.lang.String ip,
                                  int port,
                                  java.lang.String hostName,
                                  java.lang.String usrName,
                                  java.lang.String password,
                                  java.lang.String clientID)
        Builds connection
        Parameters:
        ip - Service IP
        port - Port Number
        hostName - Virtual Host Name
        usrName - Username
        password - Password
        clientID - The custom client name. Users can use it to distinguish who is sending messages
        Returns:
        Whether the connection is success
      • disconnection

        public void disconnection()
        Disconnect
      • newSender

        public AMQPSender newSender()
        Creates a sender
        Returns:
        Returns the send object
      • newReceiver

        public AMQPReceiver newReceiver(java.lang.String queueName)
        Creates a receiver
        Parameters:
        queueName - queue name
        Returns:
        Returns the receive port object
      • declareExchange

        public boolean declareExchange(java.lang.String name,
                                       AMQPExchangeType exchangeType)
        Declares the switch
        Parameters:
        name - Switch name
        exchangeType - Switch type
        Returns:
        Declare true if sent successfully; otherwise false.
      • deleteExchange

        public boolean deleteExchange(java.lang.String name)
        Delete the switch
        Parameters:
        name - Switch name
        Returns:
        Returns true if it is removed successfully; false otherwise.
      • declareQueue

        public boolean declareQueue(java.lang.String queueName)
        Declare the queue
        Parameters:
        queueName - queue name
        Returns:
        Declare true if sent successfully; otherwise false.
      • deleteQueue

        public boolean deleteQueue(java.lang.String queueName)
        Delete the queue
        Parameters:
        queueName - queue name
        Returns:
        Returns true if it is removed successfully; false otherwise.
      • bindQueue

        public boolean bindQueue(java.lang.String exchange,
                                 java.lang.String queue,
                                 java.lang.String bindingKey)
        Bind the queue and switch through the specified routingkey
        Parameters:
        exchange - Switch name
        queue - queue name
        bindingKey - The key used for binding
        Returns:
        True, if successful; otherwise false.
      • unbindQueue

        public boolean unbindQueue(java.lang.String queue,
                                   java.lang.String exchange,
                                   java.lang.String bindingKey)
        Remove the binding between queue and switch
        Parameters:
        queue - queue name
        exchange - Switch name
        bindingKey - The key used to bind the queue and switch
        Returns:
        True, if successful; otherwise false.