|
1 | 1 | --- |
2 | 2 | title: "Service Bus" |
3 | | -description: API coverage for Microsoft.ServiceBus in LocalStack for Azure. |
| 3 | +description: Get started with Azure Service Bus on LocalStack |
4 | 4 | template: doc |
5 | 5 | --- |
6 | 6 |
|
7 | 7 | import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
8 | 8 |
|
| 9 | +## Introduction |
| 10 | + |
| 11 | +Azure Service Bus is a fully managed enterprise message broker that supports queues and publish/subscribe topics. |
| 12 | +It helps decouple distributed systems and build reliable asynchronous messaging workflows. |
| 13 | +Service Bus is commonly used for command processing, event distribution, and integration between independent services. For more information, see [What is Azure Service Bus?](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-overview) |
| 14 | + |
| 15 | +LocalStack for Azure provides a local environment for building and testing applications that make use of Azure Service Bus. |
| 16 | +The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Service Bus's integration with LocalStack. |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +This guide is designed for users new to Service Bus and assumes basic knowledge of the Azure CLI and our `azlocal` wrapper script. |
| 21 | + |
| 22 | +Start your LocalStack container using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). |
| 23 | + |
| 24 | +:::note |
| 25 | +As an alternative to using the `azlocal` CLI, users can run: |
| 26 | + |
| 27 | +`azlocal start-interception` |
| 28 | + |
| 29 | +This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API. |
| 30 | +To revert this configuration, run: |
| 31 | + |
| 32 | +`azlocal stop-interception` |
| 33 | + |
| 34 | +This reconfigures the `az` CLI to send commands to the official Azure management REST API. At this time, there is no full parity between `azlocal` and `az` commands after running `az start-interception`. Therefore, this technique is not fully interchangeable. |
| 35 | +::: |
| 36 | + |
| 37 | +### Create a resource group |
| 38 | + |
| 39 | +Create a resource group to contain your Service Bus resources: |
| 40 | + |
| 41 | +```bash |
| 42 | +azlocal group create \ |
| 43 | + --name rg-servicebus-demo \ |
| 44 | + --location westeurope |
| 45 | +``` |
| 46 | + |
| 47 | +```bash title="Output" |
| 48 | +{ |
| 49 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-servicebus-demo", |
| 50 | + "location": "westeurope", |
| 51 | + "managedBy": null, |
| 52 | + "name": "rg-servicebus-demo", |
| 53 | + "properties": { |
| 54 | + "provisioningState": "Succeeded" |
| 55 | + }, |
| 56 | + "tags": null, |
| 57 | + "type": "Microsoft.Resources/resourceGroups" |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### Create a Service Bus namespace |
| 62 | + |
| 63 | +Create a Service Bus namespace in the resource group: |
| 64 | + |
| 65 | +```bash |
| 66 | +azlocal servicebus namespace create \ |
| 67 | + --resource-group rg-servicebus-demo \ |
| 68 | + --name sbnsdoc83 \ |
| 69 | + --location westeurope \ |
| 70 | + --sku Standard |
| 71 | +``` |
| 72 | + |
| 73 | +```bash title="Output" |
| 74 | +{ |
| 75 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-servicebus-demo/providers/Microsoft.ServiceBus/namespaces/sbnsdoc83", |
| 76 | + "name": "sbnsdoc83", |
| 77 | + "location": "westeurope", |
| 78 | + "provisioningState": "Succeeded", |
| 79 | + "serviceBusEndpoint": "https://sbnsdoc83.localhost.localstack.cloud:4511", |
| 80 | + "sku": { |
| 81 | + "name": "Standard", |
| 82 | + "tier": "Standard" |
| 83 | + }, |
| 84 | + ... |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +Get and list namespaces: |
| 89 | + |
| 90 | +```bash |
| 91 | +azlocal servicebus namespace show \ |
| 92 | + --resource-group rg-servicebus-demo \ |
| 93 | + --name sbnsdoc83 |
| 94 | + |
| 95 | +azlocal servicebus namespace list \ |
| 96 | + --resource-group rg-servicebus-demo |
| 97 | +``` |
| 98 | + |
| 99 | +### Create and inspect a queue |
| 100 | + |
| 101 | +Create a queue in the namespace: |
| 102 | + |
| 103 | +```bash |
| 104 | +azlocal servicebus queue create \ |
| 105 | + --resource-group rg-servicebus-demo \ |
| 106 | + --namespace-name sbnsdoc83 \ |
| 107 | + --name orders-queue |
| 108 | +``` |
| 109 | + |
| 110 | +```bash title="Output" |
| 111 | +{ |
| 112 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-servicebus-demo/providers/Microsoft.ServiceBus/namespaces/sbnsdoc83/queues/orders-queue", |
| 113 | + "name": "orders-queue", |
| 114 | + "location": "westeurope", |
| 115 | + "status": "Active", |
| 116 | + "messageCount": 0, |
| 117 | + "maxSizeInMegabytes": 1024, |
| 118 | + ... |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +Get and list queues: |
| 123 | + |
| 124 | +```bash |
| 125 | +azlocal servicebus queue show \ |
| 126 | + --resource-group rg-servicebus-demo \ |
| 127 | + --namespace-name sbnsdoc83 \ |
| 128 | + --name orders-queue |
| 129 | + |
| 130 | +azlocal servicebus queue list \ |
| 131 | + --resource-group rg-servicebus-demo \ |
| 132 | + --namespace-name sbnsdoc83 |
| 133 | +``` |
| 134 | + |
| 135 | +### Create topic and subscription |
| 136 | + |
| 137 | +Create a topic and a subscription: |
| 138 | + |
| 139 | +```bash |
| 140 | +azlocal servicebus topic create \ |
| 141 | + --resource-group rg-servicebus-demo \ |
| 142 | + --namespace-name sbnsdoc83 \ |
| 143 | + --name orders-topic |
| 144 | + |
| 145 | +azlocal servicebus topic subscription create \ |
| 146 | + --resource-group rg-servicebus-demo \ |
| 147 | + --namespace-name sbnsdoc83 \ |
| 148 | + --topic-name orders-topic \ |
| 149 | + --name orders-sub |
| 150 | +``` |
| 151 | + |
| 152 | +```bash title="Output" |
| 153 | +{ |
| 154 | + "name": "orders-topic", |
| 155 | + "status": "Active", |
| 156 | + "subscriptionCount": 0, |
| 157 | + ... |
| 158 | +} |
| 159 | +{ |
| 160 | + "name": "orders-sub", |
| 161 | + "status": "Active", |
| 162 | + "messageCount": 0, |
| 163 | + ... |
| 164 | +} |
| 165 | +``` |
| 166 | + |
| 167 | +Get and list subscriptions: |
| 168 | + |
| 169 | +```bash |
| 170 | +azlocal servicebus topic subscription show \ |
| 171 | + --resource-group rg-servicebus-demo \ |
| 172 | + --namespace-name sbnsdoc83 \ |
| 173 | + --topic-name orders-topic \ |
| 174 | + --name orders-sub |
| 175 | + |
| 176 | +azlocal servicebus topic subscription list \ |
| 177 | + --resource-group rg-servicebus-demo \ |
| 178 | + --namespace-name sbnsdoc83 \ |
| 179 | + --topic-name orders-topic |
| 180 | +``` |
| 181 | + |
| 182 | +### Create and list subscription rules |
| 183 | + |
| 184 | +Create a SQL filter rule for the subscription: |
| 185 | + |
| 186 | +```bash |
| 187 | +azlocal servicebus topic subscription rule create \ |
| 188 | + --resource-group rg-servicebus-demo \ |
| 189 | + --namespace-name sbnsdoc83 \ |
| 190 | + --topic-name orders-topic \ |
| 191 | + --subscription-name orders-sub \ |
| 192 | + --name high-priority \ |
| 193 | + --filter-sql-expression "priority = 'high'" |
| 194 | +``` |
| 195 | + |
| 196 | +```bash title="Output" |
| 197 | +{ |
| 198 | + "name": "high-priority", |
| 199 | + "filterType": "SqlFilter", |
| 200 | + "sqlFilter": { |
| 201 | + "sqlExpression": "priority = 'high'", |
| 202 | + ... |
| 203 | + }, |
| 204 | + ... |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +List rules for the subscription: |
| 209 | + |
| 210 | +```bash |
| 211 | +azlocal servicebus topic subscription rule list \ |
| 212 | + --resource-group rg-servicebus-demo \ |
| 213 | + --namespace-name sbnsdoc83 \ |
| 214 | + --topic-name orders-topic \ |
| 215 | + --subscription-name orders-sub |
| 216 | +``` |
| 217 | + |
| 218 | +### Create and manage namespace authorization rules |
| 219 | + |
| 220 | +Create an authorization rule: |
| 221 | + |
| 222 | +```bash |
| 223 | +azlocal servicebus namespace authorization-rule create \ |
| 224 | + --resource-group rg-servicebus-demo \ |
| 225 | + --namespace-name sbnsdoc83 \ |
| 226 | + --name app-policy \ |
| 227 | + --rights Listen Send |
| 228 | +``` |
| 229 | + |
| 230 | +```bash title="Output" |
| 231 | +{ |
| 232 | + "name": "app-policy", |
| 233 | + "rights": [ |
| 234 | + "Listen", |
| 235 | + "Send" |
| 236 | + ], |
| 237 | + ... |
| 238 | +} |
| 239 | +``` |
| 240 | + |
| 241 | +List authorization rules: |
| 242 | + |
| 243 | +```bash |
| 244 | +azlocal servicebus namespace authorization-rule list \ |
| 245 | + --resource-group rg-servicebus-demo \ |
| 246 | + --namespace-name sbnsdoc83 |
| 247 | +``` |
| 248 | + |
| 249 | +List and regenerate keys: |
| 250 | + |
| 251 | +```bash |
| 252 | +azlocal servicebus namespace authorization-rule keys list \ |
| 253 | + --resource-group rg-servicebus-demo \ |
| 254 | + --namespace-name sbnsdoc83 \ |
| 255 | + --name app-policy |
| 256 | + |
| 257 | +azlocal servicebus namespace authorization-rule keys renew \ |
| 258 | + --resource-group rg-servicebus-demo \ |
| 259 | + --namespace-name sbnsdoc83 \ |
| 260 | + --name app-policy \ |
| 261 | + --key PrimaryKey |
| 262 | +``` |
| 263 | + |
| 264 | +```bash title="Output" |
| 265 | +{ |
| 266 | + "keyName": "app-policy", |
| 267 | + "primaryConnectionString": "Endpoint=https://sbnsdoc83.localhost.localstack.cloud:4511/;SharedAccessKeyName=app-policy;SharedAccessKey=...;UseDevelopmentEmulator=true", |
| 268 | + "secondaryConnectionString": "Endpoint=https://sbnsdoc83.localhost.localstack.cloud:4511/;SharedAccessKeyName=app-policy;SharedAccessKey=...;UseDevelopmentEmulator=true", |
| 269 | + ... |
| 270 | +} |
| 271 | +{ |
| 272 | + "keyName": "app-policy", |
| 273 | + "primaryConnectionString": "Endpoint=https://sbnsdoc83.localhost.localstack.cloud:4511/;SharedAccessKeyName=app-policy;SharedAccessKey=...;UseDevelopmentEmulator=true", |
| 274 | + ... |
| 275 | +} |
| 276 | +``` |
| 277 | + |
9 | 278 | ## API Coverage |
10 | 279 |
|
11 | 280 | <AzureFeatureCoverage service="Microsoft.ServiceBus" client:load /> |
0 commit comments