本文整理汇总了Java中org.springframework.amqp.rabbit.core.RabbitAdmin类的典型用法代码示例。如果您正苦于以下问题:Java RabbitAdmin类的具体用法?Java RabbitAdmin怎么用?Java RabbitAdmin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RabbitAdmin类属于org.springframework.amqp.rabbit.core包,在下文中一共展示了RabbitAdmin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkRabbitMQAMQPProtocol
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
public String checkRabbitMQAMQPProtocol(String messageAsString,
String url,
String user,
String password,
String vhost) throws Exception {
org.springframework.amqp.rabbit.connection.CachingConnectionFactory cf =
new org.springframework.amqp.rabbit.connection.CachingConnectionFactory();
URL formattedUrl = new URL("http://" + url);
cf.setHost(formattedUrl.getHost());
cf.setPort(formattedUrl.getPort());
cf.setUsername(user);
cf.setPassword(password);
cf.setVirtualHost(vhost);
RabbitAdmin admin = new RabbitAdmin(cf);
org.springframework.amqp.core.Queue queue = new org.springframework.amqp.core.Queue("myQueue");
admin.declareQueue(queue);
TopicExchange exchange = new TopicExchange("myExchange");
admin.declareExchange(exchange);
admin.declareBinding(
BindingBuilder.bind(queue).to(exchange).with("foo.*"));
RabbitTemplate template = new RabbitTemplate(cf);
template.convertAndSend("myExchange", "foo.bar", messageAsString);
String receivedMessage = template.receiveAndConvert("myQueue").toString();
return receivedMessage;
}
示例2: declareQueue
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Override
public void declareQueue() throws IOException {
RabbitAdmin rabbitAdmin = rabbitAdmin();
try {
rabbitAdmin.declareQueue(new Queue("demo2",false,false,false));
}catch (Exception e){
try {
if (406 == ((AMQImpl.Channel.Close) ((ShutdownSignalException)e.getCause().getCause()).getReason()).getReplyCode()) {
rabbitAdmin.deleteQueue("demo2");
declareQueue();
}
}catch (Exception e1){
}
log.error("e 's value : {}", e);
}
}
示例3: testDefaultRabbitConfiguration
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Test
public void testDefaultRabbitConfiguration() {
load(TestConfiguration.class);
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
RabbitMessagingTemplate messagingTemplate = this.context
.getBean(RabbitMessagingTemplate.class);
CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
assertThat(rabbitTemplate.getConnectionFactory()).isEqualTo(connectionFactory);
assertThat(getMandatory(rabbitTemplate)).isFalse();
assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
assertThat(amqpAdmin).isNotNull();
assertThat(connectionFactory.getHost()).isEqualTo("localhost");
assertThat(dfa.getPropertyValue("publisherConfirms")).isEqualTo(false);
assertThat(dfa.getPropertyValue("publisherReturns")).isEqualTo(false);
assertThat(this.context.containsBean("rabbitListenerContainerFactory"))
.as("Listener container factory should be created by default").isTrue();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:RabbitAutoConfigurationTests.java
示例4: init
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@PostConstruct
private void init() {
log.info("Initialization of RabbitConfiguration");
emsConnectionFactory = new CachingConnectionFactory();
((CachingConnectionFactory) emsConnectionFactory).setHost(brokerIp);
((CachingConnectionFactory) emsConnectionFactory).setPort(rabbitPort);
((CachingConnectionFactory) emsConnectionFactory).setUsername(emsRabbitUsername);
((CachingConnectionFactory) emsConnectionFactory).setPassword(emsRabbitPassword);
rabbitAdmin = new RabbitAdmin(emsConnectionFactory);
TopicExchange topicExchange = new TopicExchange("openbaton-exchange");
rabbitAdmin.declareExchange(topicExchange);
log.info("exchange declared");
queueName_emsRegistrator = "ems." + vnfmHelper.getVnfmEndpoint() + ".register";
rabbitAdmin.declareQueue(new Queue(queueName_emsRegistrator, durable, exclusive, autodelete));
}
示例5: testDefaultRabbitConfiguration
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Test
public void testDefaultRabbitConfiguration() {
load(TestConfiguration.class);
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
RabbitMessagingTemplate messagingTemplate = this.context
.getBean(RabbitMessagingTemplate.class);
CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class);
RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
assertEquals(connectionFactory, rabbitTemplate.getConnectionFactory());
assertEquals(rabbitTemplate, messagingTemplate.getRabbitTemplate());
assertNotNull(amqpAdmin);
assertEquals("localhost", connectionFactory.getHost());
assertTrue("Listener container factory should be created by default",
this.context.containsBean("rabbitListenerContainerFactory"));
}
示例6: waitUntilQueueIsEmpty
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
public void waitUntilQueueIsEmpty(String queueName) {
RabbitAdmin rabbitAdmin = rabbitAdmin();
Properties properties;
int count;
long t0 = System.currentTimeMillis();
long max = t0 + 1000 * 60 * 2;
long t = System.currentTimeMillis();
while (t < max) {
properties = rabbitAdmin.getQueueProperties(queueName);
count = Integer.parseInt(properties.get("QUEUE_MESSAGE_COUNT").toString());
if (count == 0) {
break;
}
try {
Thread.sleep(500L);
}
catch (InterruptedException ignore) {
}
t = System.currentTimeMillis();
}
}
示例7: declareExchange
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Test
public void declareExchange() throws Exception {
RabbitAdmin bean = (RabbitAdmin) applicationContext
.getBean("rabbitAdmin");
//
String EXCHANGE_NAME = "TEST_EXCHANGE";
TopicExchange exchange = new TopicExchange(EXCHANGE_NAME);
bean.declareExchange(exchange);
//
String QUEUE_NAME = "TEST_EXCHANGE";
Queue queue = new Queue(QUEUE_NAME, false);
bean.declareQueue(queue);
//
// binding
Binding binding = BindingBuilder.bind(queue).to(exchange)
.with(QUEUE_NAME);
System.out.println(binding);
}
示例8: configureQueue
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
/**
* Configures the queue and binding based on the messenger specific name.
*/
private void configureQueue()
{
objAdmin = new RabbitAdmin(this.objConnection);
Configuration config = this.objResources.getConfiguration();
String queueName = config.getQueuePrefix() + config.getName() + config.getQueueSuffix();
boolean queueDurability = config.getQueueDurability();
boolean queueAutoDelete = config.getQueueAutoDelete();
boolean queueExclusive = config.getQueueExclusive();
this.objQueue = new Queue(queueName, queueDurability, queueAutoDelete, queueExclusive);
this.objAdmin.declareQueue(this.objQueue);
String bindingName = config.getBindingPrefix() + config.getName() + config.getBindingSuffix();
String bindingExchange = config.getBindingExchange();
this.objBinding = new Binding(this.objQueue.getName(), DestinationType.QUEUE, bindingExchange, bindingName, null);
this.objAdmin.declareBinding(this.objBinding);
}
示例9: afterPropertiesSet
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
List<RabbitAdmin> rabbitAdmins = getMqAdmins();
for (int i = 0; i < rabbitAdmins.size(); i++) {
RabbitAdmin rabbitAdmin = rabbitAdmins.get(i);
while (true) {
if (!DEFAULT_EXCHANGE.equals(exchange)) {
break;
}
try {
rabbitAdmin.declareQueue(new Queue(routingKey, queueDurable, queueExclusive, queueAutoDelete, queueArguments));
rabbitAdmin.declareBinding(new Binding(routingKey, DestinationType.QUEUE, MQClient.DEFAULT_EXCHANGE, routingKey, bindingArguments));
break;
} catch (Exception e) {
LogUtil.warn(logger, "�������У�" + routingKey + "��ʧ��", e);
}
}
}
}
示例10: rabbitAdmin
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Bean
@Required
RabbitAdmin rabbitAdmin(String uniqueQueueName) {
RabbitAdmin admin = new RabbitAdmin(connectionFactory());
admin.setAutoStartup(true);
admin.declareExchange(eventBusExchange());
admin.declareQueue(eventStream(uniqueQueueName));
admin.declareBinding(binding(uniqueQueueName));
return admin;
}
示例11: rabbitAdmin
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Bean
@Required
RabbitAdmin rabbitAdmin() {
RabbitAdmin admin = new RabbitAdmin(connectionFactory());
admin.setAutoStartup(true);
admin.declareExchange(eventBusExchange());
admin.declareQueue(defaultStream());
admin.declareBinding(binding());
return admin;
}
示例12: rabbitAdmin
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
/**
* 配置RabbitAdmin bean
*
* @param connectionFactory
* @return
*/
@Bean
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
// 创建并返回RabbitAdmin对象
return new RabbitAdmin(connectionFactory);
}
示例13: zhihuUserDataQueue
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
/**
* 配置知乎用户资料队列 bean
*
* @param rabbitAdmin
* @return
*/
@Bean
public Queue zhihuUserDataQueue(@Autowired RabbitAdmin rabbitAdmin) {
// 创建知乎用户资料队列对象
Queue ubdQueue = new Queue("zhuhu.user.queue");
// 声明知乎用户资料队列
rabbitAdmin.declareQueue(ubdQueue);
// 返回知乎用户资料队列
return ubdQueue;
}
示例14: userBehaviorDataQueue
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
/**
* 配置知乎问题队列 bean
*
* @param rabbitAdmin
* @return
*/
@Bean
public Queue userBehaviorDataQueue(@Autowired RabbitAdmin rabbitAdmin) {
// 创建知乎问题队列对象
Queue ubdQueue = new Queue("zhuhu.question.queue");
// 声明知乎问题队列
rabbitAdmin.declareQueue(ubdQueue);
// 返回知乎问题队列
return ubdQueue;
}
示例15: commandBusRabbitAdmin
import org.springframework.amqp.rabbit.core.RabbitAdmin; //导入依赖的package包/类
@Bean
@Autowired
public RabbitAdmin commandBusRabbitAdmin(final ConnectionFactory commandBusConnectionFactory) {
log.info("Creating command bus RabbitMQ administrator template");
return new RabbitAdmin(commandBusConnectionFactory);
}