# BrokerObserver

As for the [PropertyObserver](https://docs.radicalframework.com/release-1/concepts/index-1/property-observer) or the [MementoObserver](https://docs.radicalframework.com/release-1/concepts/index-1/memento-observer) the BrokerObserver is an easy shortcut to react to message arrivals when using [the message broker](https://github.com/RadicalFx/documentation/tree/3311fbb6d65f98ece74ce84f7fde9dec2a25a7ee/messaging/message-broker.md).

```csharp
var broker = //instance of a IMessageBroker implementation.
var monitor = BrokerObserver.Using( broker )
    .WaitingFor<MySampleMessage>();
```

We can use a monitor to trigger, for example, the `CanExecuteChanged` event of a `ICommand` interface implementation:

```csharp
var broker = //instance of a IMessageBroker implementation.
var monitor = BrokerObserver.Using( broker )
    .WaitingFor<MySampleMessage>();

DelegateCommand.Create()
    .OnCanExecute( state =>
    {
        //evaluate if the command can be executed.
        return true;
    } )
    .OnExecute( state =>
    {
        //execute the command
    } )
    .AddMonitor( monitor );
```

What the above code does is to trigger the `CanExecuteChanged` logic each time a message of type `MySampleMessage` is delivered via the monitored message broker.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.radicalframework.com/release-1/concepts/index-1/broker-observer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
