Hi Ryan,
In the Push scenario, the
RoutingService can be configured for forwarding inbound (WebSphere MQ) messages to the specific
Namespace/Topic Service Bus based on the routing table.
The
BrokeredMessageProperty bag for outbound messages can be created in the custom endpoint behavior with a message inspector.
The following code snippet shows an example of this message inspector:
public class MessagePropertyActionClientInspector : IClientMessageInspector
{
public string Expression { get; set; }
void IClientMessageInspector.AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
// nothing to do
}
object IClientMessageInspector.BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
if (request.Properties.ContainsKey(BrokeredMessageProperty.Name))
{
var bmp = request.Properties[BrokeredMessageProperty.Name] as BrokeredMessageProperty;
var sra = new SqlRuleAction(this.Expression);
sra.Preprocess().Execute(bmp.Message);
}
else
{
var bmp = new BrokeredMessageProperty();
var sra = new SqlRuleAction(this.Expression);
var bm = sra.Preprocess().Execute(bmp.Message);
request.Properties.Add(BrokeredMessageProperty.Name, bmp);
}
return null;
}
}
Note, that this solution requires only config file and assembly of the above message inspector and also can be deployed on the cloud as a generic gateway/bridge
(messaging between Topics, Namespace/Topics, etc,)
The same concept can be considered for Pull scenario, where a routing service is configured as Service Bus Subscriber. In this case, the custom filter can handle
SqlExpression match for BrokeredMessagePropert bag.
The following code snippet shows a custom filter for
BrokeredMessageproperty:
public class BrokeredMessageFilter : MessageFilter
{
public string Expression { get; set; }
public BrokeredMessageFilter(string expression)
{
this.Expression = expression;
}
public override bool Match(System.ServiceModel.Channels.Message message)
{
if (message.Properties.ContainsKey(BrokeredMessageProperty.Name))
{
var bmp = message.Properties[BrokeredMessageProperty.Name] as BrokeredMessageProperty;
var filter = new SqlFilter(this.Expression);
bool bMatch = filter.Preprocess().Match(bmp.Message);
return bMatch;
}
else
{
Trace.TraceInformation("BrokeredMessageFilter: Message doesn't have object BrokeredMessageProperty");
return false;
}
}
public override bool Match(System.ServiceModel.Channels.MessageBuffer buffer)
{
throw new NotImplementedException();
}
}
Roman
Roman Kiss, MVP Connected System Developer