Publish notifications to another system
MDrivenServer event communication uses SignalR to send notifications between systems. A receiving server-side ViewModel subscribes to an event, and a publishing server-side ViewModel triggers that event.
Define the event
Use an eventguid as the shared event identifier. The documentation describes this as a unique string that makes the event unique at the instance level and that is shared by the sender and subscriber.
| Value | Used by | Meaning |
|---|---|---|
eventguid
|
Subscriber and sender | The shared identifier for the event. |
eventcookie
|
Subscriber | The value returned to the subscriber when the event is received. A suggested value is Viewmodel=SomeVM&RootId= followed by an external ID.
|
eventdata
|
Sender | An optional string. It is not currently used by an MDrivenServer receiver. |
eventRemoveAfterSend
|
Sender | An optional Boolean that defaults to false. When true, the client is notified only once.
|
Use the event as a notification signal rather than as a sensitive-data channel. If the receiver needs further details, it can follow up with an authenticated RestGet protected by AccessGroups.
Subscribe to an event
- In the receiving server-side ViewModel, create an action column named
RealtimeSubscribeToEvent. - Set
realtimehubto the MDrivenServer URL of the publishing system. Leave it blank to subscribe to the current system. - Set
eventguidto the shared event identifier. - Set
eventcookieto the information needed when the receiver handles the event, for exampleViewmodel=RefreshOrder&RootId=followed byself.externalid.
RealtimeSubscribeToEvent can be called multiple times. For a server and event-guid combination, only the latest event cookie is retained. A blank event cookie, or an event cookie equal to endsubscription, removes the subscription.
Trigger an event
- In the publishing server-side ViewModel, create an action column named
RealtimeTriggerEvent. - Set its
eventguidto the identifier shared with subscribers. - Optionally set
eventdataandeventRemoveAfterSend. - Execute the action when the publishing system needs to notify subscribers.
When the trigger action executes, the publishing MDrivenServer calls ReceiveEvent for connected listening clients that match the event GUID. Subscribers receive the event GUID, their own client cookie, and event data.
Receiver handling
For an MDrivenServer receiver, the event cookie returned by ReceiveEvent(theEventGuid, theEventCookie) is used to create a SysAsyncTicket with the ViewModel and RootId from the cookie.
A non-MDrivenServer subscriber must support the SignalR API:
method SubscribeToEvent(string eventguid, string clientcookie);
event ReceiveEvent(string eventguid, string ClientCookie, string eventData);
The non-MDrivenServer subscriber parses the client cookie that it supplied when subscribing and handles the event as needed.
Security
Events are open and unauthenticated. Do not send sensitive data over events. Use events to trigger a just-in-time RestGet protected by AccessGroups.
