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


Java Channel.basicPublish方法代碼示例

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


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

示例1: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setUsername("guest");
	factory.setPassword("guest");
	factory.setVirtualHost("/");
	factory.setHost("localhost");
	factory.setPort(5672);
	Connection newConnection = factory.newConnection();

	Channel channel = newConnection.createChannel();

	Scanner scanner = new Scanner(System.in);
	String message = "";
	while(!message.equals("exit")){
		System.out.println("Enter your message");
		message = scanner.next();
		channel.queueDeclare("flink-test", true, false, false, null);
		channel.basicPublish("", "flink-test", new BasicProperties.Builder()
				.correlationId(java.util.UUID.randomUUID().toString()).build(), message.getBytes());
	}
	
	scanner.close();
	channel.close();
	newConnection.close();
}
 
開發者ID:PacktPublishing,項目名稱:Practical-Real-time-Processing-and-Analytics,代碼行數:26,代碼來源:RMQPublisher.java

示例2: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
  ConnectionFactory factory = new ConnectionFactory();
  factory.setHost("localhost");
  Connection connection = factory.newConnection();
  Channel channel = connection.createChannel();

  channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);

  String message = getMessage(argv);

  channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8"));
  System.out.println(" [x] Sent '" + message + "'");

  channel.close();
  connection.close();
}
 
開發者ID:bmariesan,項目名稱:iStudent,代碼行數:17,代碼來源:EmitLog.java

示例3: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, InterruptedException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri("amqp://guest:[email protected]");
    factory.setConnectionTimeout(300000);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare("my-queue", true, false, false, null);

    int count = 0;

    while (count < 5000) {
        String message = "Message number " + count;

        channel.basicPublish("", "my-queue", null, message.getBytes());
        count++;
        System.out.println("Published message: " + message);

        Thread.sleep(5000);
    }
}
 
開發者ID:nyholmniklas,項目名稱:rabbitmq-tutorial,代碼行數:22,代碼來源:Publisher.java

示例4: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection conn = factory.newConnection();
    Channel channel = conn.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);

    String msg = getMessage(argv);

    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy @ HH:mm:ss");
    String sDate = sdf.format(date);

    String finalMsg = sDate + ": " + msg;

    channel.basicPublish(EXCHANGE_NAME, "", null, finalMsg.getBytes("UTF-8"));
    System.out.println("Emmited message: " + finalMsg);

    channel.close();
    conn.close();
}
 
開發者ID:VictorFerraresi,項目名稱:simple-rabbitmq-logger,代碼行數:23,代碼來源:Emitter.java

示例5: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws IOException
 * @throws TimeoutException
 * @date 2017年7月11日 下午5:53:02
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	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(TASK_QUEUE_NAME, true, false, false, null);
	// 分發信息
	for (int i = 0; i < 20; i++) {
		String message = "Hello RabbitMQ" + i;
		channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
		System.out.println("NewTask send '" + message + "'");
	}
	channel.close();
	connection.close();
}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:28,代碼來源:NewTask.java

示例6: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月13日 下午2:49:49
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {

	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.exchangeDeclare(EXCHANGE_NAME_ROUTING, "direct");// 注意是direct
	// 發送信息
	for (String routingKey : routingKeys) {
		String message = "RoutingSendDirect Send the message level:" + routingKey;
		channel.basicPublish(EXCHANGE_NAME_ROUTING, routingKey, null, message.getBytes());
		System.out.println("RoutingSendDirect Send" + routingKey + "':'" + message);
	}
	channel.close();
	connection.close();
}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:29,代碼來源:RoutingSendDirect.java

示例7: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
		ConnectionFactory factory = new ConnectionFactory();
//		factory.setHost("");
		factory.setUri("amqp://alpha.netkiller.cn");
		factory.setUsername("admin");
//		factory.setPassword("admin123");
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();

		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		String message = "Hello World!";
		channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
		System.out.println(" [x] Sent '" + message + "'");

		channel.close();
		connection.close();
	}
 
開發者ID:netkiller,項目名稱:ipo,代碼行數:18,代碼來源:RabbitMQTest.java

示例8: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

    String severity = getSeverity(argv);
    String message = getMessage(argv);

    channel.basicPublish(EXCHANGE_NAME, severity, null, message.getBytes("UTF-8"));
    System.out.println(" [x] Sent '" + severity + "':'" + message + "'");

    channel.close();
    connection.close();
  }
 
開發者ID:bmariesan,項目名稱:iStudent,代碼行數:19,代碼來源:EmitLogDirect.java

示例9: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] argv) throws Exception {
  ConnectionFactory factory = new ConnectionFactory();
  factory.setHost("localhost");
  Connection connection = factory.newConnection();
  Channel channel = connection.createChannel();

  channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

  String message = getMessage(argv);

  channel.basicPublish("", TASK_QUEUE_NAME,
      MessageProperties.PERSISTENT_TEXT_PLAIN,
      message.getBytes("UTF-8"));
  System.out.println(" [x] Sent '" + message + "'");

  channel.close();
  connection.close();
}
 
開發者ID:bmariesan,項目名稱:iStudent,代碼行數:19,代碼來源:NewTask.java

示例10: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月13日 下午2:37:37
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	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.exchangeDeclare(EXCHANGE_NAME, "fanout");// fanout表示分發,所有的消費者得到同樣的隊列信息
	// 分發信息
	for (int i = 0; i < 5; i++) {
		String message = "Hello World" + i;
		channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
		System.out.println("EmitLog Sent '" + message + "'");
	}
	channel.close();
	connection.close();

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

示例11: updateTaskStatus

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
private void updateTaskStatus(TaskStatus status) {
    logger.info("[Study = " + taskStudy + "] [Unit = "+ unitId + "] Sending task update to server. Task id = [" + task.getId() + "] status = ["+status.toString()+"]");
    final String QUEUE_NAME =  SystemConstants.UBONGO_SERVER_TASKS_STATUS_QUEUE;
    try {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(serverAddress);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        task.setStatus(status);
        RabbitData message = new RabbitData(task, MachineConstants.UPDATE_TASK_REQUEST);
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        if (logger.isDebugEnabled()) {
            logger.debug(" [!] Sent '" + message.getMessage() + "'");
        }
        channel.close();
        connection.close();
    } catch (Exception e){
        logger.error("[Study = " + taskStudy + "] [Unit = "+ unitId + "] Failed sending task status to server. Task id = [" + task.getId() + "] Status = [" +
                status.toString() + "] error: " + e.getMessage(), e);
    }
}
 
開發者ID:razreg,項目名稱:ubongo,代碼行數:23,代碼來源:RequestHandler.java

示例12: execute

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

	while (true) {
		QueueingConsumer.Delivery message = consumer.nextDelivery();
		String msg = new String(message.getBody());
		System.out.println("message received: " + msg);
		String newMsg = msg.substring(0, msg.indexOf(" shares"));
		byte[] bmsg = newMsg.getBytes();
		System.out.println("Trade fixed: " + newMsg);
		channel.basicPublish("", "trade.eq.q", null, bmsg);
	}			
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:16,代碼來源:AMQPWorkflowProcessor.java

示例13: run

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public void run(int numMsgs) throws Exception {
	Channel channel = AMQPCommon.connect();
	int queueIndex = 0;
	for (int i=0; i<numMsgs; i++) {
		long shares = ((long) ((new Random().nextDouble() * 4000) + 1));
		String text = "BUY AAPL " + shares + " SHARES";
		byte[] message = text.getBytes();
		queueIndex = (queueIndex == queues.size()-1) ? 0 : queueIndex+1;
		String routingKey = queues.get(queueIndex);
		System.out.println("sending trade: " + text);
		channel.basicPublish("", routingKey, null, message);
		Thread.sleep(1000);
	}
	
	AMQPCommon.close(channel);
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:17,代碼來源:AMQPSplitProducer.java

示例14: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException, TimeoutException {

        //建立連接工廠
        ConnectionFactory factory = new ConnectionFactory();
        //設置連接地址
        factory.setHost("seaof-153-125-234-173.jp-tokyo-10.arukascloud.io");
        factory.setPort(31084);
        //獲取連接
        Connection connection = factory.newConnection();
        //獲取渠道
        Channel channel = connection.createChannel();
        //聲明隊列,如果不存在就新建
        //參數1隊列名稱;參數2是否持久化;參數3排他性隊列,連接斷開自動刪除;參數4是否自動刪除;參數5.參數
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //發送的消息
        String message = Thread.currentThread().getName() + "Hello ";

        //參數1 交換機;參數2 路由鍵;參數3 基礎屬性;參數4 消息體
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
        System.out.println(Thread.currentThread().getName() + "[send]" + message);
        channel.close();
        connection.close();

    }
 
開發者ID:liubo6,項目名稱:demo_springboot_rabbitmq,代碼行數:25,代碼來源:Send.java

示例15: 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


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