I have a MuleClient that sends a message to a Mule flow like below but I dont see properties reflected in the mule flow in response section, what scope should I make the properties to be?
MuleMessage msg = new DefaultMuleMessage();
Map<String,Object> propertiesMap = new HashMap<String,Object>();
propertiesMap.put("name", "hello");
msg.addProperties( propertiesMap, PropertyScope.INVOCATION);
then in the flow I tried to access this property like this
message.getInvocationProperty("name")
and it returns null... What am i missing?
If you send a message to a flow using a VM (or any transport) endpoint, invocation properties will not be propagated.
You need to place the properties in the outbound scope: they will arrive in the inbound scope out of the inbound endpoint of the flow.
Since you are sending the MuleMessage to Connector (ie. inbound vm ), Invocation properties not available in your flow. MessageProperties in outbound scope wil be modified into inbound scope. so use the outbound scope, in your flow access like #[message.inboundPrperties['name']]
Related
I am able to add messages to local MSMQ using nservicebus by below code
var endpointConfiguration = new EndpointConfiguration("Samples.Msmq.Simple");
var transport = endpointConfiguration.UseTransport<MsmqTransport>();
endpointConfiguration.SendFailedMessagesTo("error");
endpointConfiguration.EnableInstallers();
endpointConfiguration.UsePersistence<InMemoryPersistence>();
var endpointInstance = await Endpoint.Start(endpointConfiguration)
.ConfigureAwait(false);
var myMessage = new MyMessage();
await endpointInstance.SendLocal(myMessage)
.ConfigureAwait(false);
But I read at some places that I can send messages to remote MSMQ, see code below
FormatName:Direct=TCP:100.100.100.12\\private$\\remoteTxn
But I am not able to figure how to send to Remote MSMQ using Nservicebus. Anyone can pitch here?
Instead of using SendLocal you need to either use Send in case of a command or Publish in case of an event.
Using Send means you need to have message routing in place, as that determines what is the destination of the message. Routing could be defined using code, or other means like external files which makes it easier for dev/ops to change the routes at runtime in future.
An overload of the Send method also accepts a destination endpoint, but it is recommended to not mix concerns and keep the routing code separate (hence not using the overload with the destination). More info here.
I have written a custom Anypoint connector (using devkit), and want it to set Inbound properties, much like the Mule HTTP connector does. MuleMessage however, does not seem to have facility to do this.
How does one mimic this behavior?
Inbound properties are immutable, It can be achieved via the MuleMessage https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/MuleMessage.html#setProperty(java.lang.String, java.lang.Object, org.mule.api.transport.PropertyScope)
However, unless your connector operation is a Message Source I wouldn't add inbound properties and instead use outbound properties.
You need to use
MuleMessage message = eventContext.getMessage();
message.setProperty("key","value",PropertyScope.INBOUND);
You can refer the API :-https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/MuleMessage.html#setProperty
https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/transport/PropertyScope.html
How do I get the source address in a message received?
The context is that I'm designing a monitor for a service bus implemented with Rebus. I use the publish - subscribe pattern thus a message is always published on a topic. The monitor subscribes to all topics in order to supervise that a service has send something and so is alive and healthy. Though in a message handler the received message don't contain any source address or information identifying the service publishing. This means it's not possible to supervise which services are alive and healthy. Of course I can create an attribute "Service" identifying the service publishing in all messages. This implies that each service have to set the attribute before publishing a message, which I find a bit cumbersome. The source address is there and can identify the service publishing.
When you're in a Rebus message handler, you can access the IMessageContext - either by having it injected by your IoC container (which is the preferrent way, because of the improved testability), or by accessing the static MessageContext.Current property.
The message context gives you access to a couple of things, where the headers of the incoming transport message can be used to get the return address of the message (which, by default, is set to the sender's input queue).
Something like this should do the trick:
public class SomeHandler : IHandleMessages<SomeMessage>
{
readonly IMessageContext _messageContext;
public class SomeHandler(IMessageContext messageContext)
{
_messageContext = messageContext;
}
public async Task Handle(SomeMessage message)
{
var headers = _messageContext.TransportMessage.Headers;
var returnAddress = headers[Headers.ReturnAddress];
// .. have fun with return address here
}
}
I'm using RabbitMQ as message broker. I have a consumer and a producer. So far I have created a payload with few primitive attributes. The problem is, as long as I need more information from the payload in my consumer, I need to change payload so I can handle in the consumer: this task at the end may be heavy.
I was wondering if I could use some kind of a Map as payload or it is not recommended? Like this, I have a generic payload.
On the other hand, we have Serializable DTO in our application. I guess I could create a Payload containing DTO?
I'm trying to figure out the best way to do it :)
if you need extra information you could use message properties:
AMQP.BasicProperties.Builder builder =
new AMQP.BasicProperties().builder();
Map<String,Object> headerMap =
new HashMap<String, Object>();
headerMap.put("mykey1", myvalue1);
headerMap.put("mykey2", myvalue2);
builder.headers(headerMap);
channel.basicPublish("","myqueue",builder.build(),"message".getBytes());
Using headerMap you can add or remove info without modify your message
hope it helps
I have a flow that I usually reference elsewhere with just a flow-ref component. I would like to test this flow by making a call directly to it with a MuleClient. Is this possible? If so, can you provide an example. Here's what I have, but it doesn't work. Obviously, it's missing the protocol that would go before 'processChanges', but I don't know what that would be in this case.
MuleClient client = new MuleClient(muleContext);
client.dispatch("processChanges", payload, null);
When running from a FunctionalTestCase you can use the method runFlow(String flowName, MuleEvent event) to execute the flow with that MuleEvent as input. HTH.