Skip to content

Commit

Permalink
improve worker mq getting started docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Aug 4, 2024
1 parent 983e11d commit 45f762d
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 12 deletions.
16 changes: 16 additions & 0 deletions MyApp/_pages/amazon-sqs-mq.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ slug: amazon-sqs-mq
title: Amazon SQS MQ
---

## Enable in an existing Web App

Use the `sqs` mixin to register an [MQ Server](/messaging) for Amazon SQS with an existing .NET App:

:::sh
x mix sqs
:::

## Worker Service Template

To start using Amazon SQS in stand-alone MQ Servers (i.e. without HTTP access) is to run the MQ Server in an ASP.NET Core Worker Service by starting from a pre-configured project template:

<worker-templates template="worker-sqs"></worker-templates>

## Manual Configuration

Support for registering Amazon Simple Queue Service (SQS) as an [MQ Server](/messaging) is available in [ServiceStack.Aws](https://www.nuget.org/packages/ServiceStack.Aws) NuGet package:

:::copy
Expand Down
37 changes: 32 additions & 5 deletions MyApp/_pages/azure-service-bus-mq.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
---
slug: azure-service-bus-mq
title: Azure Service Bus MQ
---

## Enable in an existing Web App

Use the `servicebus` mixin to register an [MQ Server](/messaging) for Azure Service Bus with an existing .NET App:

:::sh
x mix servicebus
:::

## Worker Service Template

To start using Azure Service Bus in stand-alone MQ Servers (i.e. without HTTP access) is to run the MQ Server in an ASP.NET Core Worker Service by starting from a pre-configured project template:

<worker-templates template="worker-servicebus"></worker-templates>

## Manual Configuration

Support for registering Azure Service Bus as an [MQ Server](/messaging) in ServiceStack is available in [ServiceStack.Azure](https://www.nuget.org/packages/ServiceStack.Azure) NuGet package:

:::copy
Expand All @@ -12,10 +27,22 @@ Support for registering Azure Service Bus as an [MQ Server](/messaging) in Servi
Once installed ServiceBus can be configured the same way as any other [MQ Servers](/messaging), by first registering the ServiceBus `IMessageService` provider followed by registering all ServiceStack Services you want to be able to invoke via MQ’s:

```csharp
container.Register<IMessageService>(c => new ServiceBusMqServer(ConnectionString));
[assembly: HostingStartup(typeof(MyApp.ConfigureMq))]

var mqServer = container.Resolve<IMessageService>();
mqServer.RegisterHandler<MyRequest>(ExecuteMessage);
namespace MyApp;

AfterInitCallbacks.Add(appHost => mqServer.Start());
public class ConfigureMq : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
services.AddSingleton<IMessageService>(c =>
new ServiceBusMqServer(context.Configuration.GetConnectionString("ServiceBus")));
})
.ConfigureAppHost(afterAppHostInit: appHost => {
var mqServer = appHost.Resolve<IMessageService>().Start();
// Register MQ endpoints for APIs
mqServer.RegisterHandler<MyRequest>(ExecuteMessage);
mqServer.Start();
});
}
```
19 changes: 16 additions & 3 deletions MyApp/_pages/rabbit-mq.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
---
slug: rabbit-mq
title: Rabbit MQ
---

## Enable in an existing Web App

Use the `rabbitmq` mixin to register an [MQ Server](/messaging) for Amazon SQS with an existing .NET App:

:::sh
x mix rabbitmq
:::

## Worker Service Template

To start usingRabbit MQ in stand-alone MQ Servers (i.e. without HTTP access) is to run the MQ Server in an ASP.NET Core Worker Service by starting from a pre-configured project template:

<worker-templates template="worker-rabbitmq"></worker-templates>

## ServiceStack.RabbitMq

A nice advantage of ServiceStack's message-based design is its ability to host its Services on a variety of different endpoints. This design makes it possible to host Services via [MQ Servers](/messaging), enable [SOAP support](/soap-support) in addition to ServiceStack's strong HTTP Web Services story. One MQ Server we support is the extremely popular and robust Open Source AMQP messaging broker: [Rabbit MQ](http://www.rabbitmq.com).

## Getting Started
Expand All @@ -11,8 +26,6 @@ A great way to get started with Rabbit MQ on Windows is by following the
[Rabbit MQ Windows Installation guide](https://github.com/mythz/rabbitmq-windows)
which also includes sample source code for accessing Rabbit MQ Server using the .NET [RabbitMQ.Client](https://www.nuget.org/packages/RabbitMQ.Client) on NuGet.

## ServiceStack.RabbitMq

ServiceStack builds on top of **RabbitMQ.Client** to provide concrete implementations for
[ServiceStack's high-level Messaging APIs](https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Interfaces/Messaging/)
enabling a number of messaging features including publishing and receiving messages as well as registering and processing message handlers. Like other ServiceStack providers, all MQ Servers are interchangeable, visible in the shared common [MqServerIntroTests.cs](https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.Server.Tests/Messaging/MqServerIntroTests.cs) and [MqServerAppHostTests.cs](https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.Common.Tests/Messaging/MqServerAppHostTests.cs).
Expand Down
14 changes: 14 additions & 0 deletions MyApp/_pages/redis-mq.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ slug: redis-mq
title: Redis MQ
---

## Enable in an existing Web App

Use the `redismq` mixin to register an [MQ Server](/messaging) for Amazon SQS with an existing .NET App:

:::sh
x mix redismq
:::

## Worker Service Template

To start using Redis MQ in stand-alone MQ Servers (i.e. without HTTP access) is to run the MQ Server in an ASP.NET Core Worker Service by starting from a pre-configured project template:

<worker-templates template="worker-redismq"></worker-templates>

## MQ Examples

The [Reusability ServiceStack.UseCase](https://github.com/ServiceStack/ServiceStack.UseCases/tree/master/Reusability) contains a good introductory demo of using MQ's(message-queues) in ServiceStack where the same services can be called via Web Service or via MQ. Using MQ's provide instant response times, in addition to reliable and durable execution of your services.
Expand Down
7 changes: 7 additions & 0 deletions MyApp/wwwroot/pages/amazon-sqs-mq.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import WorkerTemplates from "./templates/WorkerTemplates.mjs"

export default {
components: {
WorkerTemplates,
},
}
7 changes: 7 additions & 0 deletions MyApp/wwwroot/pages/azure-service-bus-mq.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import WorkerTemplates from "./templates/WorkerTemplates.mjs"

export default {
components: {
WorkerTemplates,
},
}
7 changes: 7 additions & 0 deletions MyApp/wwwroot/pages/rabbit-mq.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import WorkerTemplates from "./templates/WorkerTemplates.mjs"

export default {
components: {
WorkerTemplates,
},
}
7 changes: 7 additions & 0 deletions MyApp/wwwroot/pages/redis-mq.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import WorkerTemplates from "./templates/WorkerTemplates.mjs"

export default {
components: {
WorkerTemplates,
},
}
10 changes: 6 additions & 4 deletions MyApp/wwwroot/pages/templates/WorkerTemplates.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ref, computed } from "vue"
import { template } from "./Templates.mjs"

export default {
template: `<section class="not-prose w-full flex flex-col justify-center text-center">
Expand All @@ -12,7 +13,7 @@ export default {
<section class="w-full flex flex-col justify-center text-center">
<div class="mt-4 mb-2">
<div class="flex flex-wrap justify-center">
<div>
<div v-if="!template || template == 'worker-rabbitmq'">
<a class="hover:no-underline" :href="zipUrl('NetCoreTemplates/worker-rabbitmq')">
<div class="bg-white dark:bg-gray-800 px-4 py-4 mr-4 mb-4 rounded-lg shadow-lg text-center items-center justify-center hover:shadow-2xl dark:border-2 dark:border-pink-600 dark:hover:border-blue-600" style="min-width:150px">
<div class="text-center font-extrabold flex items-center justify-center mb-2">
Expand All @@ -34,7 +35,7 @@ export default {
</div>
</a>
</div>
<div>
<div v-if="!template || template == 'worker-redismq'">
<a class="hover:no-underline" :href="zipUrl('NetCoreTemplates/worker-redismq')">
<div class="bg-white dark:bg-gray-800 px-4 py-4 mr-4 mb-4 rounded-lg shadow-lg text-center items-center justify-center hover:shadow-2xl dark:border-2 dark:border-pink-600 dark:hover:border-blue-600" style="min-width:150px">
<div class="text-center font-extrabold flex items-center justify-center mb-2">
Expand All @@ -56,7 +57,7 @@ export default {
</div>
</a>
</div>
<div>
<div v-if="!template || template == 'worker-servicebus'">
<a class="hover:no-underline" :href="zipUrl('NetCoreTemplates/worker-servicebus')">
<div class="bg-white dark:bg-gray-800 px-4 py-4 mr-4 mb-4 rounded-lg shadow-lg text-center items-center justify-center hover:shadow-2xl dark:border-2 dark:border-pink-600 dark:hover:border-blue-600" style="min-width:150px">
<div class="text-center font-extrabold flex items-center justify-center mb-2">
Expand All @@ -78,7 +79,7 @@ export default {
</div>
</a>
</div>
<div>
<div v-if="!template || template == 'worker-sqs'">
<a class="hover:no-underline" :href="zipUrl('NetCoreTemplates/worker-sqs')">
<div class="bg-white dark:bg-gray-800 px-4 py-4 mr-4 mb-4 rounded-lg shadow-lg text-center items-center justify-center hover:shadow-2xl dark:border-2 dark:border-pink-600 dark:hover:border-blue-600" style="min-width:150px">
<div class="text-center font-extrabold flex items-center justify-center mb-2">
Expand All @@ -104,6 +105,7 @@ export default {
</div>
</section>
</section>`,
props: { template: String },
setup(props) {
const project = ref('MyApp')
const projectZip = computed(() => (project.value || 'MyApp') + '.zip')
Expand Down

0 comments on commit 45f762d

Please sign in to comment.