hangeDeclare方法介绍

更新时间:2023-06-22 12:22:52 阅读: 评论:0

exchangeDeclare
/**
* Declare an exchange.zhuangbility
* @e com.rabbitmq.client.AMQP.Exchange.Declare
* @e com.rabbitmq.client.AMQP.Exchange.DeclareOk
jakarta* @param exchange the name of the exchange
* @param type the exchange type
* @param durable true if we are declaring a durable exchange (the exchange will survive a rver restart)
* @param autoDelete true if the rver should delete the exchange when it is no longer in u
* @param arguments other properties (construction arguments) for the exchange
* @return a declaration-confirm method to indicate the exchange was successfully declared
* @throws java.io.IOException if an error is encountered
*/
Exchange.DeclareOk exchangeDeclare(String exchange,
String type,
boolean durable,
boolean autoDelete,
boolean internal,
Map<String, Object> arguments) throws IOException;
exchange :交换器的名称
type : 交换器的类型,常见的有direct,fanout,topic等
durable :设置是否持久化。durable设置为true时表⽰持久化,反之⾮持久化.持久化可以将交换器存⼊磁盘,在服务器重启的时候不会丢失相关信息。
autoDelete:设置是否⾃动删除。autoDelete设置为true时,则表⽰⾃动删除。⾃动删除的前提是⾄少有⼀个队列或者交换器与这个交换器绑定,之后,所有与这个交换器绑定的队列或者交换器都与此解绑。不能错误的理解—当与此交换器连接的客户端都断开连接时,RabbitMq会⾃动删除本交换器
internal:设置是否内置的。如果设置为true,则表⽰是内置的交换器,客户端程序⽆法直接发送消息到这个交换器中,只能通过交换器路由到交换器这种⽅式。
arguments:其它⼀些结构化的参数,⽐如:alternate-exchange
jago
其它⼀些重载的⽅法
BuiltinExchangeType
lamp怎么读public enum BuiltinExchangeType {
快速美白小窍门DIRECT("direct"),FANOUT("fanout"),TOPIC("topic"),HEADERS("headers");
private final String type;
BuiltinExchangeType(String type){
}
public String getType(){
return type;
}
}nineteen
type可以⽤上⾯的这个代替
Exchange.DeclareOk exchangeDeclare(String exchange, String type)throws IOException;
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type)throws IOException;
Exchange.DeclareOk exchangeDeclare(String exchange, String type,boolean durable)throws IOException;
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type,boolean durable,boolean autoDelete,        Map<String, Object> arguments)throws IOException;
Exchange.DeclareOk exchangeDeclare(String exchange,
BuiltinExchangeType type,
boolean durable,
boolean autoDelete,
boolean internal,
inchcapeMap<String, Object> arguments)throws IOException;
exchangeDeclareNoWait⽅法
/**
* Like {@link Channel#exchangeDeclare(String, String, boolean, boolean, java.util.Map)} but
* ts nowait parameter to true and returns nothing (as there will be no respon from
* the rver).
*
* @param exchange the name of the exchange
* @param type the exchange type
* @param durable true if we are declaring a durable exchange (the exchange will survive a rver restart)
* @param autoDelete true if the rver should delete the exchange when it is no longer in u
* @param internal true if the exchange is internal, i.e. can't be directly
* published to by a client.
* @param arguments other properties (construction arguments) for the exchange
* @throws java.io.IOException if an error is encountered
*/
void exchangeDeclareNoWait(String exchange,
String type,
boolean durable,
boolean autoDelete,
boolean internal,
Map<String, Object> arguments)throws IOException;
exchangeDeclareNoWait⽐exchangeDeclare⽅法默认多设置了⼀个nowait参数
.nowait(true)
transmit(new AMQCommand(new Exchange.Declare.Builder()
.homo
exchange(exchange)
.type(type)
.durable(durable)
.autoDelete(autoDelete)
.internal(internal)
.arguments(arguments)
.passive(fal)
.nowait(true)
.build()));
nowait是Exchange.Declare命令的参数
public static class Exchange {
public interface Declare extends Method {
int getTicket();
String getExchange();
String getType();
boolean getPassive();
boolean getDurable();
boolean getAutoDelete();
decentlyboolean getInternal();
boolean getNowait();
Map<String,Object>getArguments();
// Builder for instances of Exchange.Declare
public static final class Builder
{
private int ticket =0;
private String exchange;
private String type ="direct";
private boolean passive =fal;
private boolean durable =fal;
private boolean autoDelete =fal;
private boolean internal =fal;
private boolean nowait =fal;
private Map<String,Object> arguments = null;
public Builder(){}
...
意思是不需要服务器返回,返回值为void,⽽普通的exchangeDeclare返回的是Exchange.DeclareOk,客户端声明⼀交换器后,需要等待服务器的返回
nowait:在声明完⼀个交换器后,实际上服务器还未完成交换器的创建,那么客户端接着使⽤这个交换吕,必然发⽣异常,exchangeDeclarePassive⽅法
/**
* Declare an exchange passively; that is, check if the named exchange exists.
* @param name check the existence of an exchange named this
multipla* @throws IOException the rver will rai a 404 channel exception if the named exchange does not exist.
*/
Exchange.DeclareOk exchangeDeclarePassive(String name) throws IOException;
主要有来检测相应的交换器是否存在。如果存在则正常返回;如果不存在则抛出异常:404 channel exception,同时channel也会被 关闭删除exchangeDelete
/**
* Delete an exchange
* @e com.rabbitmq.client.AMQP.Exchange.Delete
* @e com.rabbitmq.client.AMQP.Exchange.DeleteOk
* @param exchange the name of the exchange
* @param ifUnud true to indicate that the exchange is only to be deleted if it is unud
* @return a deletion-confirm method to indicate the exchange was successfully deleted
* @throws java.io.IOException if an error is encountered
*/
Exchange.DeleteOk exchangeDelete(String exchange,boolean ifUnud)throws IOException;
ifUnud ⽤来设置是否在交换器没有被使⽤的情况下删除。
true:则只有在此交换器没有被使⽤的情况下才会被删除.
fal:⽆论如何这个交换器都要被删除

本文发布于:2023-06-22 12:22:52,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1013382.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:交换器   设置   是否   删除   服务器
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图