首页 \ 问答 \ 默认rabbitmq交换类型(Default rabbitmq exchange type)

默认rabbitmq交换类型(Default rabbitmq exchange type)

根据我的理解,默认情况下, RabbitMQ服务器创建交换类型Direct即如果我创建交换没有提供任何类型它将创建类型直接交换。
有什么办法可以改变默认行为,即默认交换类型为fanout而不是Direct即如果交换类型丢失,则交换应该是类型FanoutDirect


As per my understanding RabbitMQ server by default creates exchange of type Direct i.e If I create exchange without providing any type it will create exchange of type Direct.
Is there any way by which I can change default behavior i.e default exchange type as fanout instead of Direct i.e if exchange type is missing then exchange should be of type Fanout notDirect


原文:https://stackoverflow.com/questions/49928771
更新时间:2022-05-23 22:05

最满意答案

首先,一个简单的例子 - 我的方法看起来像这样(使用问题中的其他所有内容):

public class Class1D {

    private int degree;
    private int [] coefficient;
    // private double evaluation=0; (Remove this!)

    public Class1D(int degree){
        this.degree =degree;
    }

    public Class1D(int degree, int[] a){

        this.degree =degree;
        this.coefficient = a.clone();
    }

    public int []getCoefficient() {
        return coefficient;  
    }

    public double Evaluathepolynomial(double value){

        // This will be the output:
        double total=0;

        // For each degree..
        for (int i =0; i<this.degree; i++)
        {

            // The current one is..
            double evaluation = Math.pow(value,i) *this.coefficient[i];

            // Add it into the total:
            // (same as total+=evaluation)
            total = total + evaluation;

        }

        // We're done! Return that total:
        return total;

    }
}

这是怎么回事?

首先要记住的是变量一次只能保持一件事。 所以,如果你做这样的事情:

double a;
a=1;
a=2;
a=14;

// a is now 14.

A将是14 。 那些其他的路线基本上被忽略了,因为a只会持有你最后决定的任何东西。

好吧,让我们看看你的原始循环:

 for (int i =0; i<this.degree; i++)
 {
     this.evaluation= Math.pow(value,i) *this.coefficient[i];
     this.evaluation+= evaluation;

 }

 return evaluation;

首先,请记住,它所做的一切都是在循环内重复这些行 - 不管你指定多少次。 因此,为了便于可视化,我们假设“度数”为3并解开循环 - 这意味着复制这些行并删除循环:

 // i=0
 this.evaluation= Math.pow(value,0) *this.coefficient[0];
 this.evaluation+= evaluation;

 // i=1
 this.evaluation= Math.pow(value,1) *this.coefficient[1];
 this.evaluation+= evaluation;

 // i=2
 this.evaluation= Math.pow(value,2) *this.coefficient[2];
 this.evaluation+= evaluation;

其次,值得一提的是, this.evaluation evaluationevaluation是指同一个变量

希望它开始变得更清楚一些 - 循环的每次迭代都完全覆盖了前一次的结果。 让我们进一步简化它:

// i=0
evaluation=2; // It's 2
evaluation+=evaluation; // 2+2; it's now 4

// i=1
evaluation=10; // It's 10. It's now like that 4 never even happened!
evaluation+=evaluation; // 10+10; it's now 20

这意味着在您的原始代码中, 只有最后一个系数至关重要4度,最后系数为2,那32发生如下:

 this.evaluation= Math.pow(2,3) *2; // 16
 this.evaluation+= evaluation; // evaluation = 16+16 = 32

简单的路线是引入第二个变量,所以解决方案更像这样:

 a=0; // a is now 0

 b=14;
 a+=b; // a is now 14

 b=20;
 a+=b; // a is now 34

或者使用一个变量的其他替代方法是直接将其添加到:

 a+=14; // a is now 14

 a+=20; // a is now 34

这看起来像这样:

total += Math.pow(value,i) *this.coefficient[i];

调试

希望以上内容帮助我们明确了发生了什么,以及为什么上面的方法和您的答案都有效。 但重要的是,一次一个脚本遍历代码并清楚地说明应该做什么是成功调试的重要组成部分。 许多人发现真的很方便,因为你很快就会发现这种方式出了什么问题。 在println调用中添加断点或添加断点来仔细检查它实际上是否在执行您所描述的内容,这一点至关重要。


Firstly, a quick example - my approach would look something like this (using everything else in the question):

public class Class1D {

    private int degree;
    private int [] coefficient;
    // private double evaluation=0; (Remove this!)

    public Class1D(int degree){
        this.degree =degree;
    }

    public Class1D(int degree, int[] a){

        this.degree =degree;
        this.coefficient = a.clone();
    }

    public int []getCoefficient() {
        return coefficient;  
    }

    public double Evaluathepolynomial(double value){

        // This will be the output:
        double total=0;

        // For each degree..
        for (int i =0; i<this.degree; i++)
        {

            // The current one is..
            double evaluation = Math.pow(value,i) *this.coefficient[i];

            // Add it into the total:
            // (same as total+=evaluation)
            total = total + evaluation;

        }

        // We're done! Return that total:
        return total;

    }
}

What's going on?

The first thing to keep in mind is that a variable can only hold on to one thing at a time. So, if you do something like this:

double a;
a=1;
a=2;
a=14;

// a is now 14.

A will be 14. Those other lines are essentially being ignored, because a will only hold whatever it was you set to it last.

Alright so let's take a look at your original loop:

 for (int i =0; i<this.degree; i++)
 {
     this.evaluation= Math.pow(value,i) *this.coefficient[i];
     this.evaluation+= evaluation;

 }

 return evaluation;

Firstly, keep in mind that all it's doing is repeating those lines inside the loop over and over - however many times you specify. So, for easy visualising, let's say "degree" is 3 and unravel the loop - that just means duplicate the lines and remove the loop:

 // i=0
 this.evaluation= Math.pow(value,0) *this.coefficient[0];
 this.evaluation+= evaluation;

 // i=1
 this.evaluation= Math.pow(value,1) *this.coefficient[1];
 this.evaluation+= evaluation;

 // i=2
 this.evaluation= Math.pow(value,2) *this.coefficient[2];
 this.evaluation+= evaluation;

Secondly, it's also worth mentioning that this.evaluation and evaluation are referring to the same variable.

Hopefully it's starting to be a little clearer as to what's going on - each iteration of the loop is completely overwriting the results of the previous one. Let's simplify it further:

// i=0
evaluation=2; // It's 2
evaluation+=evaluation; // 2+2; it's now 4

// i=1
evaluation=10; // It's 10. It's now like that 4 never even happened!
evaluation+=evaluation; // 10+10; it's now 20

This meant that in your original code, only the last coefficient ever mattered. With a degree of 4 and that last coefficient being 2, that 32 occured like this:

 this.evaluation= Math.pow(2,3) *2; // 16
 this.evaluation+= evaluation; // evaluation = 16+16 = 32

The simple route is to introduce a second variable, so the solution is more like this:

 a=0; // a is now 0

 b=14;
 a+=b; // a is now 14

 b=20;
 a+=b; // a is now 34

Or the other alternative using one variable is to directly add it in:

 a+=14; // a is now 14

 a+=20; // a is now 34

That would look like this:

total += Math.pow(value,i) *this.coefficient[i];

Debugging

Hopefully the above helped make it clear what was going on, and why both the approach above and your answer are working. Importantly though, stepping through your code a line at a time and clearly stating what it's supposed to be doing is a big component of successful debugging. Many people find it really convenient to literally speak it out (I know I do!) because you'll very quickly spot what's going wrong that way. Dropping in println calls or adding breakpoints to double check it's actually doing what you describe is vital too.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。