本文整理匯總了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);
}