Skip to content

Commit

Permalink
Merge pull request #640 from lilla28/fix/message-router-doc-highlights
Browse files Browse the repository at this point in the history
fix(messaging-documentation) - Fix Javascript Gatsby highlights
  • Loading branch information
lilla28 authored May 8, 2024
2 parents 085b86f + 3ef7123 commit 7827e11
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions site/content/documentation/v0.1.0-alpha.4/message-router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ var services = new ServiceCollection()
```

In Javascript/Typescript you should import the `createMessageRouter` from the `@morgan-stanley/composeui-messaging-client` library.
```Javascript
```javascript
import { createMessageRouter } from "@morgan-stanley/composeui-messaging-client";
```

Use `createMessageRouter()` to instantiate the MessageRouter client in a ComposeUI application. It will connect to the MessageRouter hosted by the container when you call `connect()` on the client.
```Javascript
```javascript
let client = createMessageRouter();
```

Expand All @@ -81,7 +81,7 @@ To directly connect to the server, you can call the `ConnectAsync` method from t
In .NET you can connect to the server endpoint, by passing a `CancellationToken` as well which can control the connection lifetime. Not setting that will fallback on its default value which is `CancellationToken.None`.

In Javascript/Typescript you are also able to achieve this by calling the `connect` method which returns a `Promise<void>`.
```Javascript
```javascript
await client.connect();
```

Expand All @@ -104,7 +104,7 @@ Use the subscribe method of the client to set a handler on a topic. The message
It returns an `IAsyncDisposable` object.

- Javascript/TypeScript
```Javascript
```javascript
client.subscribe('exampleTopic', (message) => {
const payload = JSON.parse(message.payload);
console.log(payload);
Expand All @@ -115,15 +115,15 @@ Use the subscribe method of the client to set a handler on a topic. The message
#### Publish a message
Use the publish method of the client to publish a message to a topic. The payload of the message must be a string. The following example creates a JSON string out of an object, and publishes it to the "exampleTopic" topic.
- .NET
```csharp
```csharp
await _messageRouter.PublishAsync(
'exampleTopic',
MessageBuffer.Factory.CreateJson(payloadObject, _jsonSerializerOptions));
```
where `_jsonSerializerOptions` is your own defined serializer options to be used with the `JsonSerializer`.

- Javascript/Typescript
```Javascript
```javascript
await client.publish('exampleTopic', JSON.stringify(payloadObject));
```

Expand All @@ -138,7 +138,7 @@ Use the invoke method of the client to invoke a registered service's handler and
This results an `MessageBuffer` -see [reference](https://github.com/morganstanley/ComposeUI/blob/main/src/messaging/dotnet/src/Core/MessageBuffer.cs), type where you could call the `ReadJson<T>` extension method to convert the buffer to the expected type that the called service should return eg. `var result = resultBuffer.ReadJson<MyClass>(_jsonSerializerOptions);`.

- Javascript/Typescript
```Javascript
```javascript
const resultBuffer = await this.messageRouterClient.invoke('exampleTopic', JSON.stringify(payloadObject));
const result = <MyClass>JSON.parse(resultBuffer);
```
Expand All @@ -157,7 +157,7 @@ Use the register service method to register a service by providing its name and
```

- Javascript/Typescript
```Javascript
```javascript
await client.registerService(
"exampleTopic",
() => Promise.resolve(),
Expand All @@ -172,7 +172,7 @@ Use the unregister service method if you want to remove the service registration
```

- Javascript/Typescript
```Javascript
```javascript
await client.unregisterService("exampleTopic");
```

Expand All @@ -192,7 +192,7 @@ The invoke request in this case would be solved "locally".
```

- Javascript/Typescript
```Javascript
```javascript
await client.registerEndpoint("exampleTopic", (endpoint, payload, context) => {
console.log("Payload is handled.");
return Promise.resolve();
Expand All @@ -209,7 +209,7 @@ Use the unregister endpoint method if you want to remove an endpoint.
```

- Javascript/Typescript
```Javascript
```javascript
await client.unregisterEndpoint("exampleTopic");
```

Expand Down

0 comments on commit 7827e11

Please sign in to comment.