@Override public void run(String... args) throws Exception { System.out.println("Sending message..."); rabbitTemplate.convertAndSend(Application.topicExchangeName, "foo.bar.baz", "Hello from RabbitMQ!"); receiver.getLatch().await(10000, TimeUnit.MILLISECONDS); }
/** * 站内信 * @param mm */ public void sendMessage(MiaoshaMessage mm) { // String msg = RedisService.beanToString(mm); log.info("send message:"+"11111"); rabbitTemplate.convertAndSend(MQConfig.EXCHANGE_TOPIC,"miaosha_*", "111111111"); }
/** * 站内信 * @param */ public void sendRegisterMessage(MiaoShaMessageVo miaoShaMessageVo) { String msg = RedisService.beanToString(miaoShaMessageVo); log.info("send message:{}" , msg); rabbitTemplate.convertAndSend(MQConfig.MIAOSHATEST,msg); // rabbitTemplate.convertAndSend(MQConfig.EXCHANGE_TOPIC,"miaosha_*", msg); } }
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { String message = "Hello World!"; this.template.convertAndSend(queue.getName(), message); System.out.println(" [x] Sent '" + message + "'"); }
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { StringBuilder builder = new StringBuilder("Hello to "); if (this.index.incrementAndGet() == keys.length) { this.index.set(0); } String key = keys[this.index.get()]; builder.append(key).append(' '); builder.append(this.count.incrementAndGet()); String message = builder.toString(); template.convertAndSend(topic.getName(), key, message); System.out.println(" [x] Sent '" + message + "'"); }
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { StringBuilder builder = new StringBuilder("Hello to "); if (this.index.incrementAndGet() == 3) { this.index.set(0); } String key = keys[this.index.get()]; builder.append(key).append(' '); builder.append(this.count.incrementAndGet()); String message = builder.toString(); template.convertAndSend(direct.getName(), key, message); System.out.println(" [x] Sent '" + message + "'"); }
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { StringBuilder builder = new StringBuilder("Hello"); if (dots.getAndIncrement() == 3) { dots.set(1); } for (int i = 0; i < dots.get(); i++) { builder.append('.'); } builder.append(count.incrementAndGet()); String message = builder.toString(); template.convertAndSend(fanout.getName(), "", message); System.out.println(" [x] Sent '" + message + "'"); }
@Scheduled(fixedDelay = 1000, initialDelay = 500) public void send() { StringBuilder builder = new StringBuilder("Hello"); if (dots.getAndIncrement() == 3) { dots.set(1); } for (int i = 0; i < dots.get(); i++) { builder.append('.'); } builder.append(count.incrementAndGet()); String message = builder.toString(); template.convertAndSend(queue.getName(), message); System.out.println(" [x] Sent '" + message + "'"); }
/** * 发布消息至Broker,通常由定时器扫描发送 */ public void publish(Event event, String exchange, String routeKey, CorrelationData correlationData) { Preconditions.checkNotNull(event); Preconditions.checkNotNull(exchange); Preconditions.checkNotNull(routeKey); HibernateValidators.throwsIfInvalid(event); rabbitTemplate.convertAndSend(exchange, routeKey, event, correlationData); }
@Override public void run(String... args) throws Exception { System.out.println("Sending message..."); rabbitTemplate.convertAndSend(SpringbootRabbitmqApplication.queueName, "Hello from RabbitMQ!"); receiver.getLatch().await(10000, TimeUnit.MILLISECONDS); context.close(); }
@Scheduled(fixedDelay = 10000L) public void send() { this.rabbitTemplate.convertAndSend("foo", "hello"); }
@Scheduled(fixedDelay = 1000L) public void send() { this.rabbitTemplate.convertAndSend("foo", "hello"); }
public void send() { rabbitTemplatenew.setConfirmCallback(this); String msg="callbackSender : i am callback sender"; System.out.println(msg ); CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); System.out.println("callbackSender UUID: " + correlationData.getId()); this.rabbitTemplatenew.convertAndSend("exchange", "topic.messages", msg, correlationData); }
/** * 立即生效配置 * * @return */ @Override public Boolean applyZuulRoute() { EntityWrapper wrapper = new EntityWrapper(); wrapper.eq(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL); List<SysZuulRoute> routeList = selectList(wrapper); redisTemplate.opsForValue().set(CommonConstant.ROUTE_KEY, routeList); rabbitTemplate.convertAndSend(MqQueueConstant.ROUTE_CONFIG_CHANGE, 1); return Boolean.TRUE; } }
contextJson.put("product", "Pig4Cloud"); log.info("短信发送请求消息中心 -> 手机号:{} -> 验证码:{}", mobile, code); rabbitTemplate.convertAndSend(MqQueueConstant.MOBILE_CODE_QUEUE, new MobileMsgTemplate( mobile,
rabbitTemplate.convertAndSend(MqQueueConstant.MOBILE_SERVICE_STATUS_CHANGE, new MobileMsgTemplate( CollUtil.join(monitorMobilePropertiesConfig.getMobile().getMobiles(), ","), rabbitTemplate.convertAndSend(MqQueueConstant.DINGTALK_SERVICE_STATUS_CHANGE, text);
@Test public void testManual() { AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(this.container); adapter.setBeanFactory(mock(BeanFactory.class)); adapter.setOutputChannel(foo); adapter.afterPropertiesSet(); adapter.start(); this.template.convertAndSend("Hello, world"); Message<?> out = bar.receive(5000); assertNotNull(out); assertEquals(1, out.getPayload()); out = bar.receive(5000); assertNotNull(out); assertEquals(2, out.getPayload()); out = bar.receive(5000); assertNotNull(out); assertEquals(3, out.getPayload()); out = bar.receive(1000); assertNull(out); adapter.stop(); }
/** * 测试Direct模式. * * @param p the p * @return the response entity */ public void direct(String p) { CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); rabbitTemplate.convertAndSend("DIRECT_EXCHANGE", "DIRECT_ROUTING_KEY", p, correlationData); }
@Test public void testDifferentTypes() throws InterruptedException { Foo1 foo = new Foo1(); foo.setBar("bar"); this.jsonRabbitTemplate.convertAndSend("differentTypes", foo); assertTrue(this.service.latch.await(10, TimeUnit.SECONDS)); assertThat(this.service.foos.get(0), instanceOf(Foo2.class)); assertEquals("bar", ((Foo2) this.service.foos.get(0)).getBar()); assertThat(TestUtils.getPropertyValue(this.registry.getListenerContainer("different"), "concurrentConsumers"), equalTo(2)); }
@Test public void testConnect() throws Exception { RabbitAdmin admin = new RabbitAdmin(this.lqcf); Queue queue = new Queue(UUID.randomUUID().toString(), false, false, true); admin.declareQueue(queue); ConnectionFactory targetConnectionFactory = this.lqcf.getTargetConnectionFactory("[" + queue.getName() + "]"); RabbitTemplate template = new RabbitTemplate(targetConnectionFactory); template.convertAndSend("", queue.getName(), "foo"); assertEquals("foo", template.receiveAndConvert(queue.getName())); admin.deleteQueue(queue.getName()); }