lpp.rabbitmq.original.EndPoint.java Source code

Java tutorial

Introduction

Here is the source code for lpp.rabbitmq.original.EndPoint.java

Source

/*
 * Copyright 1999-2016 feidee.com All right reserved. This software is the
 * confidential and proprietary information of feidee.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with feidee.com.
 */
package lpp.rabbitmq.original;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * ???
 * @author lipanpan
 * @time 2016224
 */
public abstract class EndPoint {

    protected Channel channel;

    protected Connection connection;

    protected String endPointName;

    public EndPoint(String endpointName, RabbitMqConfig config) throws IOException, TimeoutException {

        this.endPointName = endpointName;

        // ?
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(config.getHost());
        factory.setPort(config.getPort());
        factory.setUsername(config.getUserName());
        factory.setPassword(config.getPassword());

        // getting a connection
        connection = factory.newConnection();

        // creating a channel
        channel = connection.createChannel();

        // declaring a queue for this channel. If queue does not exist,
        // it will be created on the server.
        channel.queueDeclare(endpointName, false, false, false, null);
    }

    /**
     * channelconnection???
     * @throws IOException
     * @throws TimeoutException
     */
    public void close() throws IOException, TimeoutException {
        this.channel.close();
        this.connection.close();
    }

}