简体   繁体   English

入站属性m创建

[英]inbound property mule create

Why does this code allow someone to create an inbound message property in a Message Processor (like a Java component) 为什么此代码允许某人在消息处理器(如Java组件)中创建入站消息属性

message.setProperty("myProperty", PropertyScope.INBOUND" );

but this does not 但这不是

<set-property value="100" propertyName="myProperty" />

Per documentation, only message source should be able to create inbound property, then why is a Java component able to set inbound message property? 根据文档,仅消息源应该能够创建入站属性,那么为什么Java组件能够设置入站消息属性?

You are right - that does violate the documented behavior of inbound properties. 您是对的,这确实违反了记录的入站属性的行为。 As further, proof if you try to set an inbound property using the expression component: 此外,请证明您是否尝试使用表达式组件设置入站属性:

<expression-component>
  message.inboundProperties['foo'] = 'bar'
</exporession-component>

At runtime will throw the following error: 在运行时将引发以下错误:

Exception stack is:
1. The inbound message property "foo" cannot be added, updated or removed 
   because inbound message properties are immutable (java.lang.UnsupportedOperationException)
  org.mule.el.context.MessagePropertyMapContext:47 (null)

However Javadoc for setProperty says: 但是setProperty的 Javadoc说:

Set a property on the message. 在消息上设置一个属性。 End-users should prefer more scope-specific methods for readability. 最终用户应更倾向于范围特定的方法以提高可读性。 This one is more intended for programmatic scope manipulation and Mule internal use. 该代码更适合于程序范围操纵和Mule内部使用。

So the takeaway is that setProperty is for internal Mule use, you should use setInvocationProperty, setOutboundProperty or setSessionProperty. 因此,外卖是setProperty供内部Mule使用,您应该使用setInvocationProperty,setOutboundProperty或setSessionProperty。 That is interesting to know because I'm sure I have used setProperty before. 知道这很有趣,因为我确定我以前曾经使用过setProperty。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM