當前位置: 首頁>>代碼示例>>Java>>正文


Java Channel.basicQos方法代碼示例

本文整理匯總了Java中com.rabbitmq.client.Channel.basicQos方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.basicQos方法的具體用法?Java Channel.basicQos怎麽用?Java Channel.basicQos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.rabbitmq.client.Channel的用法示例。


在下文中一共展示了Channel.basicQos方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicQos(1);
	channel.basicConsume("trade.eq.q", false, consumer);

	int numMsgs = args.length > 0 ? new Integer(args[0]).intValue() : 1;
	for (int i=0; i<numMsgs; i++) {
		QueueingConsumer.Delivery msg = consumer.nextDelivery();
		System.out.println("message received: " + new String(msg.getBody()));
		Thread.sleep(1000);
		channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
	}			
	
	AMQPCommon.close(channel);
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:17,代碼來源:AMQPReceiver.java

示例2: start

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public void start(Connection connection) {
	try {
		active = true;
		Channel channel = connection.createChannel();
		QueueingConsumer consumer = new QueueingConsumer(channel);
		channel.basicQos(1);
		channel.basicConsume("trade.eq.q", false, consumer);
		while (active) {
			QueueingConsumer.Delivery msg = consumer.nextDelivery();
			System.out.println("message received: " + new String(msg.getBody()));
			Thread.sleep(1000);
			channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
		}
		channel.close();
	} catch (Exception e) {
		e.printStackTrace();
	}	
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:19,代碼來源:AMQPConsumer.java

示例3: openChannel

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * Open channel
 */
private Channel openChannel(Connection conn) throws IOException {
    log.trace("Creating channel...");
    Channel channel = conn.createChannel();
    log.debug("Created channel: {}", channel);
    // setup the basicQos
    if (consumer.getEndpoint().isPrefetchEnabled()) {
        channel.basicQos(consumer.getEndpoint().getPrefetchSize(), consumer.getEndpoint().getPrefetchCount(),
                consumer.getEndpoint().isPrefetchGlobal());
    }

    // This really only needs to be called on the first consumer or on
    // reconnections.
    if (consumer.getEndpoint().isDeclare()) {
        consumer.getEndpoint().declareExchangeAndQueue(channel);
    }
    return channel;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:RabbitConsumer.java

示例4: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @throws InterruptedException
 * @throws ConsumerCancelledException
 * @throws ShutdownSignalException
 */
public static void main(String[] args) throws IOException, TimeoutException, ShutdownSignalException,
		ConsumerCancelledException, InterruptedException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection 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);

	System.out.println("RPCServer Awating RPC request");
	while (true) {
		QueueingConsumer.Delivery delivery = consumer.nextDelivery();
		BasicProperties props = delivery.getProperties();
		BasicProperties replyProps = new AMQP.BasicProperties.Builder().correlationId(props.getCorrelationId())
				.build();

		String message = new String(delivery.getBody(), "UTF-8");
		int n = Integer.parseInt(message);

		System.out.println("RPCServer fib(" + message + ")");
		String response = "" + fib(n);
		channel.basicPublish("", props.getReplyTo(), replyProps, response.getBytes());
		channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
	}
}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:40,代碼來源:RPCServer.java

示例5: initChannel

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
private void initChannel(Channel channel) throws IOException {
    channel.basicQos(1);
    // this.channel.exchangeDeclare(this.exchange, TOPIC);
    Map<String, Object> args = new HashMap<>();
    args.put("x-expires", 180000); // Three minutes
    channel.queueDeclare(QUEUE_NAME, true, true, true, args);
    channel.queueBind(QUEUE_NAME, NOVA_EXCHANGE, ROUTING_KEY);
    channel.queueBind(QUEUE_NAME, NEUTRON_EXCHANGE, ROUTING_KEY);
    channel.queueBind(QUEUE_NAME, KEYSTONE_EXCHANGE, ROUTING_KEY);
    channel.queueBind(this.queue, this.exchange, this.routingKey);
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:12,代碼來源:RabbitMQClient.java

示例6: dispatchMessages

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public void dispatchMessages() throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicQos(1);
	channel.basicConsume("trade.eq.q", false, consumer);

	while (true) {
		QueueingConsumer.Delivery msg = consumer.nextDelivery();
		channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
		new Thread(new POJOThreadProcessor(
			this, new String(msg.getBody()))).start();
		numThreads++;
		System.out.println("Threads: " + numThreads);
	}			
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:16,代碼來源:AMQPThreadDispatcher.java

示例7: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicQos(1);
	channel.basicConsume("trade.eq.q", false, consumer);

	while (true) {
		QueueingConsumer.Delivery msg = consumer.nextDelivery();
		Thread.sleep(2000);
		System.out.println("Trade placed: " + new String(msg.getBody()));
		channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
	}			
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:14,代碼來源:AMQPThreadConsumer.java

示例8: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicQos(1);
	channel.basicConsume("trade.eq.q", false, consumer);

	while (true) {
		QueueingConsumer.Delivery msg = consumer.nextDelivery();
		System.out.println("message received: " + new String(msg.getBody()));
		Thread.sleep(2000);
		channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
	}			
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:14,代碼來源:AMQPContConsumer.java

示例9: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	Channel channel = AMQPCommon.connect();
	QueueingConsumer consumer = new QueueingConsumer(channel);
	channel.basicQos(1);
	channel.basicConsume(args[0], false, consumer);

	while (true) {
		QueueingConsumer.Delivery msg = consumer.nextDelivery(1000);
		if (msg == null) break;
		System.out.println("message received: " + new String(msg.getBody()));
		Thread.sleep(100);
		channel.basicAck(msg.getEnvelope().getDeliveryTag(), false);
	}
	
	System.exit(0);
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:17,代碼來源:AMQPSplitConsumer.java

示例10: createListenerContainer

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
@Override
protected Connection createListenerContainer() throws Exception {

    log.debug("Creating connection");
    Connection conn = endpoint.connect(executorService);

    log.debug("Creating channel");
    Channel channel = conn.createChannel();
    // setup the basicQos
    if (endpoint.isPrefetchEnabled()) {
        channel.basicQos(endpoint.getPrefetchSize(), endpoint.getPrefetchCount(),
                        endpoint.isPrefetchGlobal());
    }

    //Let the server pick a random name for us
    DeclareOk result = channel.queueDeclare();
    log.info("Using temporary queue name: {}", result.getQueue());
    setReplyTo(result.getQueue());

    //TODO check for the RabbitMQConstants.EXCHANGE_NAME header
    channel.queueBind(getReplyTo(), endpoint.getExchangeName(), getReplyTo());

    consumer = new RabbitConsumer(this, channel);
    consumer.start();

    return conn;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:28,代碼來源:TemporaryQueueReplyManager.java

示例11: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws IOException
 * @throws TimeoutException
 * @date 2017年7月11日 下午5:55:38
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	final ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	final Channel channel = connection.createChannel();

	channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
	System.out.println("Worker1  Waiting for messages");

	// 每次從隊列獲取的數量
	//channel.basicQos(1);保證一次隻分發一個 
	channel.basicQos(1);

	final Consumer consumer = new DefaultConsumer(channel) {
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws IOException {
			String message = new String(body, "UTF-8");
			System.out.println("Worker1  Received '" + message + "'");
			try {
				//throw new Exception();
				doWork(message);
			} catch (Exception e) {
				channel.abort();
			} finally {
				System.out.println("Worker1 Done");
				channel.basicAck(envelope.getDeliveryTag(), false);
			}
		}
	};
	//autoAck是否自動回複,
	//如果為true的話,每次生產者隻要發送信息就會從內存中刪除,
	//那麽如果消費者程序異常退出,那麽就無法獲取數據,
	//我們當然是不希望出現這樣的情況,所以才去手動回複,
	//每當消費者收到並處理信息然後在通知生成者。
	//最後從隊列中刪除這條信息。
	//如果消費者異常退出,如果還有其他消費者,
	//那麽就會把隊列中的消息發送給其他消費者,
	//如果沒有,等消費者啟動時候再次發送。
	boolean autoAck = false;
	// 消息消費完成確認
	channel.basicConsume(TASK_QUEUE_NAME, autoAck, consumer);

}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:56,代碼來源:Work1.java

示例12: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws IOException
 * @throws TimeoutException
 * @date 2017年7月11日 下午5:55:38
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	final ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	final Channel channel = connection.createChannel();

	channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
	System.out.println("Worker2 Waiting for messages");

	// 每次從隊列獲取的數量
	//channel.basicQos(1);保證一次隻分發一個 
	channel.basicQos(1);

	final Consumer consumer = new DefaultConsumer(channel) {
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws IOException {
			String message = new String(body, "UTF-8");
			System.out.println("Worker2 Received '" + message + "'");
			try {
				//throw new Exception();
				doWork(message);
			} catch (Exception e) {
				channel.abort();
			} finally {
				System.out.println("Worker2 Done");
				channel.basicAck(envelope.getDeliveryTag(), false);
			}
		}
	};
	//autoAck是否自動回複,
	//如果為true的話,每次生產者隻要發送信息就會從內存中刪除,
	//那麽如果消費者程序異常退出,那麽就無法獲取數據,
	//我們當然是不希望出現這樣的情況,所以才去手動回複,
	//每當消費者收到並處理信息然後在通知生成者。
	//最後從隊列中刪除這條信息。
	//如果消費者異常退出,如果還有其他消費者,
	//那麽就會把隊列中的消息發送給其他消費者,
	//如果沒有,等消費者啟動時候再次發送。
	boolean autoAck = false;
	// 消息消費完成確認
	channel.basicConsume(TASK_QUEUE_NAME, autoAck, consumer);

}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:56,代碼來源:Work2.java


注:本文中的com.rabbitmq.client.Channel.basicQos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。