默认rabbitmq交换类型(Default rabbitmq exchange type)
根据我的理解,默认情况下,
RabbitMQ
服务器创建交换类型Direct
即如果我创建交换没有提供任何类型它将创建类型直接交换。
有什么办法可以改变默认行为,即默认交换类型为fanout
而不是Direct
即如果交换类型丢失,则交换应该是类型Fanout
不Direct
As per my understanding
RabbitMQ
server by default creates exchange of typeDirect
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 asfanout
instead ofDirect
i.e if exchange type is missing then exchange should be of typeFanout
notDirect
原文:https://stackoverflow.com/questions/49928771
最满意答案
首先,一个简单的例子 - 我的方法看起来像这样(使用问题中的其他所有内容):
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
evaluation
和evaluation
是指同一个变量 。希望它开始变得更清楚一些 - 循环的每次迭代都完全覆盖了前一次的结果。 让我们进一步简化它:
// 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, becausea
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
andevaluation
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.
相关问答
更多-
计算SUM的SUM(Calculate the SUM of a SUM)[2022-04-07]
从Select列表中删除Group By和非聚合列 SELECT SUM(total_reseller_sales) as Total FROM sales_report_resellers rs INNER JOIN resellers r ON rs.resellerid = r.resellerid WHERE (sid > '282' AND sid < '292') AND r.insidesales = 1 Remove Group By and non aggregate col ... -
我想你想要这个: tapply(q,# the variable to be summarized v,# the variable that defines the bins function(x) # the function to calculate the summary statistics within each bin sum(x)/length(x)) I think you want this: tapply(q,# the variab ...
-
这应该工作: SELECT room, SUM( CASE WHEN booked_stop_time - booked_start_time > 0 THEN booked_stop_time - booked_start_time END ) AS booked, SUM( CASE WHEN used_stop_time - used_start_time > 0 THEN used_stop_time - used_start_ti ...
-
首先,一个简单的例子 - 我的方法看起来像这样(使用问题中的其他所有内容): public class Class1D { private int degree; private int [] coefficient; // private double evaluation=0; (Remove this!) public Class1D(int degree){ this.degree =degree; } public Class1 ...
-
让我们来看看: DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("ID", typeof(decimal))); dt.Columns.Add(new DataColumn("SUM-ID", typeof(decimal), "ID + ID")); var row = dt.NewRow(); row["ID"] = 2; dt.Rows.Add(row); var val = dt.Rows[0]["SUM-ID"]; 结果 ...
-
您可以将其重写为 #define NP_MAXREADY (((~0u)<<1)>>1) 那么你会发现内部移位操作是完全无用的,因为它的唯一影响是移出最高位 #define NP_MAXREADY ((~0u)>>1) 这反过来又是什么都没有 #define NP_MAXREADY (UINT_MAX/2) 除了在另一个答案中指出,这不是INT_MAX ,因为首先这里是一个unsigned ,所以类型是不同的。 然后,有signed与unsigned的表示可能会有填充位,因此您永远无法确定这两个值是否 ...
-
尝试这个: SELECT name, definition FROM sys.computed_columns 当然 - 目录视图在其他列中还包含更多有用的信息! Try this: SELECT name, definition FROM sys.computed_columns and of course - that catalog view also contains a lot more useful information in its other columns!
-
awk '/Time in seconds/ {s+=$5;c++} END{print s/c}' bt.B.1.log >t1avg.dat s是时间的总和, c是计数。 因此, s/c是平均值。 awk '/Time in seconds/ {s+=$5;c++} END{print s/c}' bt.B.1.log >t1avg.dat s is the sum of the times and c is the count. Thus, s/c is the average.
-
正则表达式,用验证计算CRC中的内容(Regular expression, calculate something like CRC in it with validations)[2022-03-29]
这对我来说看起来不像常用语言,所以答案是否定的,你不能这样做。 如果列表的大小是固定的,或者你需要以10为模的数字之和,那么它将非常复杂,但可能是可行的。 一般来说,一种语言,其中单词由数字列表组成,并且它们的总和不规则,因为它通常不能满足抽取引理 。 从积极的方面来说,没有正则表达式就可以轻松完成。 This doesn't look like a regular language to me, so the answer is no, you can't do it. If the size of th ... -
触发器正在计算错误的总和,从而产生意外结果(Triggers are calculating the wrong sum, giving unexpected results)[2023-04-03]
此行为的原因是插入的数据仅在触发器完成执行时提交到数据库。 因此,当两个插入操作(5和7)并行执行触发器时,它们会在事务中读取数据,即提交的数据与其自己的事务中所做的更改,但不会在任何其他正在进行的事务中进行更改。 对于两个事务,表A中的已提交数据总计最多为20,并且添加了在其自己的事务中插入的记录。 对于一个这是5,对于另一个它是7,但由于这些记录尚未提交,另一个事务没有看到这个值。 这就是为什么一个是20 + 5,另一个是20 + 7。 然后,事务一个接一个地更新表B(因为表B将在更新期间被锁定,直到事 ...