|
In the example above WebORB unconditionally delivers
all MSMQ messages to every Flex client. It
is also possible to add conditional logic in the
message delivery chain. Starting with the version
3.2.0.0, WebORB supports message selectors. A
selector is a special server-side class associated
with a messaging destination. If a selector is
configured, WebORB
passes every message received from the queue to the
selector object. The selector can either transform
the message or instruct WebORB to cancel message
delivery to a consumer.
A selector class must implement the following
interface:
namespace Weborb.Messaging.V3
{
public interface IMessageSelector
{
/**
* Passes the selector value from consumer.
* Consumer instances can assign a value to the
* 'selector' property of the Consumer class
*/
void
setClientSelectorValue(
String
selectorValue );
/**
* Process a message originally sent by a Flex
publisher.
* Return null to cancel message delivery.
*/
Object processClientMessage(
V3Message message );
/**
* Process a message sent from a non-Flex client.
* Return null to cancel message delivery.
*/
Object processServerMessage(
Object message );
/**
* Set the id of a client associated with this selector
*/
void setClientID(
String clientID );
}
} |
Below is a sample implementation
which can be used with the example from this
article. Selector is invoked every time before a
message is sent to a client. The selector can either
change the message to be sent to the client or
return null to cancel message delivery.
|
using
System;
using
Weborb.Messaging.V3;
using
Weborb.V3Types;
namespace
ORBExamples.Messaging
{
public
class
CustomSelector :
IMessageSelector
{
private
string clientID;
public void setClientSelectorValue(
String
selectorValue )
{
}
public
object
processClientMessage(
V3Message message )
{
// no
filtering for messages published from Flex
clients
return message;
}
public
object
processServerMessage(
object message )
{
Car
carObj = (Car)
message;
//
rollback a few miles.
// don't tell
anyone we did it:
carObj.Mileage /= 2;
return
carObj;
}
public
void setClientID(
string clientID
)
{
this.clientID
= clientID;
}
}
} |
To configure a selector class, enter
its full type name in the <selector> node of your
destination configuration in WEB-INF/flex/messaging-config.xml. For example, to register the selector
shown above, use the following configuration:
<destination id="mqtoflex">
<properties>
<selector>ORBExamples.Messaging.CustomSelector</selector>
<msmq>
<path>.\private$\weborb-mqpush</path>
<!-- zero means 'do not send past messages'.
Set to -1 to
receive previously sent messages -->
<deliverPastMessages>0</deliverPastMessages>
<BasePriority>0</BasePriority>
<Category>00000000-0000-0000-0000-000000000000</Category>
<Label>WebORB
MessageQueue for Messages from Windows
client</Label>
<MaximumQueueSize>4294967295</MaximumQueueSize>
<UseJournalQueue>false</UseJournalQueue>
<MaximumJournalSize>4294967295</MaximumJournalSize>
</msmq>
</properties>
<channels>
<channel ref="weborb-rtmp"/>
</channels>
</destination> |
It is also possible to identify a
client with an ID. The subscribe() method can
optionally accept client ID as a string value.
WebORB passes client ID to the message selector
using the setClientID() call.
Additionally, if a consumer needs to pass a value
into the selector in the runtime, it can use the
selector property available in the consumer class.
As soon as a value is assigned, the client sends it
to the server and WebORB passes it to the
destination's selector object. |