当前位置: 首页>>代码示例>>Java>>正文


Java MessageProperties类代码示例

本文整理汇总了Java中com.rabbitmq.client.MessageProperties的典型用法代码示例。如果您正苦于以下问题:Java MessageProperties类的具体用法?Java MessageProperties怎么用?Java MessageProperties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MessageProperties类属于com.rabbitmq.client包,在下文中一共展示了MessageProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.rabbitmq.client.MessageProperties; //导入依赖的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

示例2: main

import com.rabbitmq.client.MessageProperties; //导入依赖的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

示例3: send

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
/****
 * This method is used to publish the message to RabbitMQ
 * @param routingKey
 * @param msg is Eiffel Event
 * @throws IOException
 */
public void send(String routingKey, String msg) throws IOException {

    Channel channel = giveMeRandomChannel();
    channel.addShutdownListener(new ShutdownListener() {
        public void shutdownCompleted(ShutdownSignalException cause) {
            // Beware that proper synchronization is needed here
            if (cause.isInitiatedByApplication()) {
                log.debug("Shutdown is initiated by application. Ignoring it.");
            } else {
                log.error("Shutdown is NOT initiated by application.");
                log.error(cause.getMessage());
                boolean cliMode = Boolean.getBoolean(PropertiesConfig.CLI_MODE);
                if (cliMode) {
                    System.exit(-3);
                }
            }
        }
    });

    BasicProperties msgProps = MessageProperties.BASIC;
    if (usePersitance)
        msgProps = MessageProperties.PERSISTENT_BASIC;

    channel.basicPublish(exchangeName, routingKey, msgProps, msg.getBytes());
    log.info("Published message with size {} bytes on exchange '{}' with routing key '{}'", msg.getBytes().length,
            exchangeName, routingKey);
}
 
开发者ID:Ericsson,项目名称:eiffel-remrem-publish,代码行数:34,代码来源:RabbitMqProperties.java

示例4: publishEventToExchange

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
private void publishEventToExchange(final Channel channel, final String exchangeName, final String routingKey, final String eventDescription) throws IOException {
    final byte[] messageBodyBytes = eventDescription.getBytes();
    try {
        channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes);
    } catch (final IOException e) {
        s_logger.warn("Failed to publish event " + routingKey + " on exchange " + exchangeName + "  of message broker due to " + e.getMessage(), e);
        throw e;
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:10,代码来源:RabbitMQEventBus.java

示例5: main

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
public static void main(String[] argv) throws java.io.IOException, 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);
//		�ַ���Ϣ
		for(int i = 0 ; i < 5; i++){
			String message = "Hello World! " + i;
			channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
			System.out.println(" [x] Sent '" + message + "'");
		}
		channel.close();
		connection.close();
	}
 
开发者ID:chwshuang,项目名称:rabbitmq,代码行数:17,代码来源:NewTask.java

示例6: test_topic

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
@Test
public void test_topic() {
  Topic topic = Topic.builder()
      .durable(false)
      .exchange("exchange")
      .autoDelete(false)
      .exclusive(false)
      .name("name")
      .properties(MessageProperties.PERSISTENT_TEXT_PLAIN)
      .build();
      
  assertTrue(!topic.durable());
  assertTrue(!topic.autoDelete());
  assertTrue(!topic.exclusive());
  assertEquals(topic.exchange(), "exchange");
  assertEquals(topic.name(), "name");
  assertEquals(topic.properties(), MessageProperties.PERSISTENT_TEXT_PLAIN);
  
  
}
 
开发者ID:scalecube,项目名称:RabbitMQ-gateway,代码行数:21,代码来源:TopicTest.java

示例7: convert

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
private static AMQP.BasicProperties convert(String name) throws RuleException {
    switch (name) {
        case "BASIC":
            return MessageProperties.BASIC;
        case "TEXT_PLAIN":
            return MessageProperties.TEXT_PLAIN;
        case "MINIMAL_BASIC":
            return MessageProperties.MINIMAL_BASIC;
        case "MINIMAL_PERSISTENT_BASIC":
            return MessageProperties.MINIMAL_PERSISTENT_BASIC;
        case "PERSISTENT_BASIC":
            return MessageProperties.PERSISTENT_BASIC;
        case "PERSISTENT_TEXT_PLAIN":
            return MessageProperties.PERSISTENT_TEXT_PLAIN;
        default:
            throw new RuleException("Message Properties: '" + name + "' is undefined!");
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:19,代码来源:RabbitMqMsgHandler.java

示例8: main

import com.rabbitmq.client.MessageProperties; //导入依赖的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);
        //发送的消息
        for (int i = 0; i < 10; i++) {

            String message = "Hello";
            int num = ThreadLocalRandom.current().nextInt(10);
            String append = "";
            for (int j = 0; j < num; j++) {
                append = append + ".";
            }
            message = message + (append);

            //参数1 交换机;参数2 路由键;参数3 基础属性,(持久化方式);参数4 消息体
            channel.basicPublish("", QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println(Thread.currentThread().getName() + "[send]" + message);
        }
        channel.close();
        connection.close();


    }
 
开发者ID:liubo6,项目名称:demo_springboot_rabbitmq,代码行数:35,代码来源:NewTask.java

示例9: send

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
/**
 * Send messages over queue and DB.
 * @param request request from the client
 */
public String send(Request request, String clientIp) {
    Measurement measurement =
            new Measurement(request.getClientId(), clientIp, request.getCommand(),
                    request.getResponseAddress(),request.getRepetitions(), request.getRepetitionInterval(),
                    request.getProcessors(), request.getAdapter());
    String measurementString = JsonConverter.objectToJsonString(measurement);

    //put data in DB
    String id = mm.pushJson(measurementString);
    MDC.put("jobId", id);
    logger.info("Json pushed in DB: " + measurementString);
    MDC.remove("jobId");

    try {
        channel.basicPublish("", queueName,
                MessageProperties.PERSISTENT_TEXT_PLAIN,
                JsonConverter.objectToJsonString(new Job(id)).getBytes());
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return id;
}
 
开发者ID:IrimieBogdan,项目名称:DistributedMonitoring,代码行数:27,代码来源:Sender.java

示例10: sendMessage

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
public void sendMessage(File messageFile) throws IOException, ShutdownSignalException, InterruptedException{
	InputStream is = new FileInputStream(messageFile);

    // Get the size of the file
    long length = messageFile.length();
    if (length > Integer.MAX_VALUE) {
    	throw new IOException("Input File ("+messageFile.getName()+") is to large! ");
    }
    byte[] messageBodyBytes = new byte[(int)length];
    int offset = 0;
    int numRead = 0;
    while (offset < messageBodyBytes.length
           && (numRead=is.read(messageBodyBytes, offset, messageBodyBytes.length-offset)) >= 0) {
        offset += numRead;
    }
    if (offset < messageBodyBytes.length) {
        throw new IOException("Could not completely read file "+messageFile.getName());
    }
    is.close();
	this.channel.basicPublish(this.ExchangeName, this.RoutingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes) ;
	
}
 
开发者ID:Data-to-Insight-Center,项目名称:komadu,代码行数:23,代码来源:Sender.java

示例11: sendMessage

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
public static void sendMessage(String message)
        throws java.io.IOException {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(ConfigurationLoader.getInstance().getRabbitmqNodename());
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

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

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

    channel.close();
    connection.close();
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-mazerunner,代码行数:19,代码来源:Worker.java

示例12: main

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
public static void main(String[] args) throws Exception {


        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Down Stream server ip (localhost):");
        String server_ip = br.readLine();
        if (server_ip.equalsIgnoreCase("")) {
            server_ip = "localhost";
        }

        ConnectionFactory factory_down = new ConnectionFactory();
        factory_down.setHost(server_ip);
        factory_down.setUsername("test");
        factory_down.setPassword("test");
        factory_down.setVirtualHost("poc");
        Connection connection_down = factory_down.newConnection();
        System.out.println("Connected to Down Stream node: " + server_ip);
        final Channel channel_down = connection_down.createChannel();
        final String exchange = "service";
        channel_down.exchangeDeclare(exchange, "topic", true);
        channel_down.basicPublish(exchange, "r1.gis", MessageProperties.PERSISTENT_BASIC, "better".getBytes());

    }
 
开发者ID:Gsantomaggio,项目名称:rabbitmqexample,代码行数:24,代码来源:Events.java

示例13: sendInternal

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
private Queue<byte[]> sendInternal(byte[] message) throws IOException {
    try {
        channel.basicPublish(DEFAULT_EXCHANGE, this.queueName, MessageProperties.PERSISTENT_BASIC, message);
    } catch (Exception e) {
        // try to reconnect and re-try once...
        connect();
        channel.basicPublish(DEFAULT_EXCHANGE, this.queueName, MessageProperties.PERSISTENT_BASIC, message);
        // if that fails, it simply throws an exception
    }
    return this;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:12,代码来源:RabbitQueueFactory.java

示例14: sendWorkQueueMessage

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
/**
 * 发送消息
 *
 * @param message 消息内容 不能为空
 */
public void sendWorkQueueMessage(String message) throws IOException, TimeoutException {
    RabbitMQChannel channel = new RabbitMQChannel().channel();
    System.out.println(channel);
    channel.getChannel().queueDeclare(WORK_QUEUE_NAME, true, false, false, null);
    channel.getChannel().basicPublish("", WORK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
    System.out.println("发送workQueue消息:" + message);
    channel.close();
}
 
开发者ID:mumudemo,项目名称:mumu-rabbitmq,代码行数:14,代码来源:RabbitMQWorkQueue.java

示例15: sendQueue

import com.rabbitmq.client.MessageProperties; //导入依赖的package包/类
private void sendQueue(QueueName queueName, RabbitMessage rm) throws Exception {
    if (rm == null || queueName == null) {
        return;
    }
    initQueueChannel();
    String _queueName = queueName.getNameByEnvironment(environment);
    Transaction trans = Cat.newTransaction("RabbitMQ Message", "PUBLISH-QUEUE-" + _queueName);
    Cat.logEvent("mq send queue", _queueName, Event.SUCCESS,rm.toJsonStr());
    try {
        queueChannel.queueDeclare(_queueName, true, false, false, null);
        queueChannel.basicPublish("", _queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, rm.toJsonStr().getBytes("UTF-8"));
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("SEND SUCCESS:[queue:{},message:{}]", _queueName, rm.toJsonStr());
        }
        Cat.logMetricForCount("PUBLISH-QUEUE-" + _queueName); // 统计请求次数, 可以查看对应队列中放入了多少信息
        trans.setStatus(Transaction.SUCCESS);
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("SEND ERROR:[queue:{},message:{},exception:{}]", _queueName, rm.toJsonStr(), e);
        }
        String err = queueName + "  rabbitmq发送消息异常";
        Cat.logError(err, e);
        trans.setStatus(e);
        throw new AsuraRabbitMqException(err, e);
    } finally {
        trans.complete();
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:29,代码来源:RabbitMqSendClient.java


注:本文中的com.rabbitmq.client.MessageProperties类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。