Skip to content

Commit e4c1ca3

Browse files
authored
.NET Standard samples (Azure#109)
Port of the NETFX samples to .NET Standard and then port of the simplifications back to NETFX.
1 parent f7aa63e commit e4c1ca3

File tree

304 files changed

+26838
-9478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+26838
-9478
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ local.properties
5050
.scala_dependencies
5151
.worksheet
5252

53+
54+
### IDEA
55+
.project
56+
*.iml
57+
5358
### VisualStudioCode ###
5459
.vscode/*
5560
!.vscode/settings.json

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
# Microsoft Azure Service Bus
66

7-
To learn more about Azure Service Bus, please visit our [marketing page](https://azure.microsoft.com/services/service-bus/).
7+
To learn more about Azure Service Bus, please visit our [start page](https://azure.microsoft.com/services/service-bus/).
88

99
This repository is intended to be used for the following:
10-
* Service side issues and feature requests
10+
* Service side issues and feature requests. Please file issues here in this repository.
1111
* [Samples](./samples/readme.md)
12-
* Documentation issues
12+
* Reports of documentation issues
1313

14-
If you are looking for a specific client library, see the following:
14+
If you are looking for the code of a specific client library, see the following:
1515
* [.NET Standard](https://github.com/azure/azure-service-bus-dotnet)
1616
* [Java](https://github.com/azure/azure-service-bus-java)
1717

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceRoot}/AutoForward/bin/Debug/netcoreapp2.0/AutoForward.dll",
14+
"args": [],
15+
"cwd": "${workspaceRoot}/AutoForward",
16+
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17+
"console": "internalConsole",
18+
"stopAtEntry": false,
19+
"internalConsoleOptions": "openOnSessionStart"
20+
},
21+
{
22+
"name": ".NET Core Attach",
23+
"type": "coreclr",
24+
"request": "attach",
25+
"processId": "${command:pickProcess}"
26+
}
27+
]
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"taskName": "build",
8+
"type": "process",
9+
"command": "msbuild",
10+
"args": [
11+
// Ask msbuild to generate full paths for file names.
12+
"/property:GenerateFullPaths=true",
13+
"/t:build"
14+
],
15+
"group": "build",
16+
"presentation": {
17+
// Reveal the output only if unrecognized errors occur.
18+
"reveal": "silent"
19+
},
20+
// Use the standard MS compiler pattern to detect errors, warnings and infos
21+
"problemMatcher": "$msCompile"
22+
}
23+
]
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net462;netcoreapp2.0</TargetFrameworks>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<None Remove="readme.md" />
9+
</ItemGroup>
10+
<ItemGroup>
11+
<Compile Include="..\common\Main.cs" Link="Main.cs" />
12+
</ItemGroup>
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="2.0.0" />
15+
<PackageReference Include="Microsoft.CSharp" Version="4.4.0" />
16+
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
17+
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
18+
<PackageReference Include="System.Linq" Version="4.3.0" />
19+
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.1" />
20+
</ItemGroup>
21+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//
2+
// Copyright © Microsoft Corporation, All Rights Reserved
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
11+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
12+
// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
13+
// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
14+
//
15+
// See the Apache License, Version 2.0 for the specific language
16+
// governing permissions and limitations under the License.
17+
18+
namespace AutoForward
19+
{
20+
using Microsoft.Azure.ServiceBus;
21+
using Microsoft.Azure.ServiceBus.Core;
22+
using System;
23+
using System.Text;
24+
using System.Threading.Tasks;
25+
26+
// This sample demonstrates how to automatically forward messages from a queue,
27+
// subscription, or deadletter queue into another queue or topic.
28+
// The sample assumes prior setup of a topology of Service Bus entities
29+
// as described in the accompanying README file.
30+
public class Program : MessagingSamples.Sample
31+
{
32+
public async Task Run(string connectionString)
33+
{
34+
Console.WriteLine("\nSending messages\n");
35+
36+
// Create sender and send message M1 into the source topic
37+
var topicSender = new MessageSender(connectionString, "AutoForwardSourceTopic");
38+
await topicSender.SendAsync(CreateMessage("M1"));
39+
40+
// Create sender and send message M2 directly into the target queue
41+
var queueSender = new MessageSender(connectionString, "AutoForwardTargetQueue");
42+
await queueSender.SendAsync(CreateMessage("M2"));
43+
44+
// Create the receiver on the target queue
45+
Console.WriteLine("\nReceiving messages\n");
46+
var targetQueueReceiver = new MessageReceiver(connectionString, "AutoForwardTargetQueue");
47+
for (int i = 0; i < 2; i++)
48+
{
49+
// We are expecting twp messages to arrive into the target queue.
50+
// 1) Message M2 has been sent directly
51+
// 2) Message M1 has been auto-forwarded from a subscription on the source topic
52+
var message = await targetQueueReceiver.ReceiveAsync(TimeSpan.FromSeconds(10));
53+
if (message != null)
54+
{
55+
await this.PrintReceivedMessage(message);
56+
await targetQueueReceiver.CompleteAsync(message.SystemProperties.LockToken);
57+
}
58+
else
59+
{
60+
throw new Exception("Expected message not received.");
61+
}
62+
}
63+
await targetQueueReceiver.CloseAsync();
64+
}
65+
66+
async Task PrintReceivedMessage(Message receivedMessage)
67+
{
68+
Console.ForegroundColor = ConsoleColor.Yellow;
69+
await Console.Out.WriteLineAsync(string.Format("Received message:\n" + "\tLabel:\t{0}\n" + "\tBody:\t{1}\n", receivedMessage.Label, Encoding.UTF8.GetString(receivedMessage.Body)));
70+
foreach (var p in receivedMessage.UserProperties)
71+
{
72+
await Console.Out.WriteLineAsync(string.Format("\tProperty:\t{0} = {1}", p.Key, p.Value));
73+
}
74+
Console.ResetColor();
75+
}
76+
77+
// Create a new Service Bus message.
78+
public static Message CreateMessage(string label)
79+
{
80+
// Creat1e a Service Bus message.
81+
var msg = new Message(Encoding.UTF8.GetBytes("This is the body of message \"" + label + "\"."));
82+
msg.UserProperties.Add("Priority", 1);
83+
msg.UserProperties.Add("Importance", "High");
84+
msg.Label = label;
85+
msg.TimeToLive = TimeSpan.FromSeconds(90);
86+
return msg;
87+
}
88+
89+
public static int Main(string[] args)
90+
{
91+
try
92+
{
93+
var app = new Program();
94+
app.RunSample(args, app.Run);
95+
}
96+
catch (Exception e)
97+
{
98+
Console.WriteLine(e.ToString());
99+
return 1;
100+
}
101+
return 0;
102+
}
103+
104+
}
105+
}
106+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Auto-Forward
2+
3+
This sample demonstrates how to automatically forward messages from a queue,
4+
subscription, or deadletter queue into another queue or topic.
5+
6+
Refer to the main [README](../README.md) document for setup instructions.
7+
8+
## What is Auto Forwarding?
9+
10+
The Auto-Forwarding feature enables you to chain the a Topic Subscription or a
11+
Queue to destination Queue or Topic that is part of the same Service Bus
12+
namespace. When the feature is enabled, Service Bus automatically moves any
13+
messages arriving in the source Queue or Subscription into the destination Queue
14+
or Topic.
15+
16+
Auto-Forwarding allows for a range of powerful routing patterns inside Service
17+
Bus, including decoupling of send and receive locations, fan-in, fan-out, and
18+
application-defined partitioning.
19+
20+
[Read more about auto-forwarding in the documentation.][1]
21+
22+
## Sample code
23+
24+
The sample generates 2 messages: M1, and M2. M1 is sent to a source topic
25+
with one subscription, from which it is forwarded to a destination queue. M2 is
26+
sent to the destination queue directly.
27+
28+
The setup template creates the topology for this example as shown here. Note
29+
that the topic whose subscription auto-forwards into the target queue is made
30+
dependent on the target queue, so that the queue is created first. The
31+
connection between the two entitries is made with the ```forwardTo```property of
32+
the subscription pointing to the target queue.
33+
34+
``` JSON
35+
{
36+
"apiVersion": "[variables('apiVersion')]",
37+
"name": "AutoForwardSourceTopic",
38+
"type": "topics",
39+
"dependsOn": [
40+
"[concat('Microsoft.ServiceBus/namespaces/',
41+
parameters('serviceBusNamespaceName'))]",
42+
"AutoForwardTargetQueue",
43+
],
44+
"properties": {},
45+
"resources": [
46+
{
47+
"apiVersion": "[variables('apiVersion')]",
48+
"name": "Forwarder",
49+
"type": "subscriptions",
50+
"dependsOn": [ "AutoForwardSourceTopic" ],
51+
"properties": {
52+
"forwardTo": "AutoForwardTargetQueue"
53+
},
54+
"resources": []
55+
}
56+
]
57+
},
58+
{
59+
"apiVersion": "[variables('apiVersion')]",
60+
"name": "AutoForwardTargetQueue",
61+
"type": "queues",
62+
"dependsOn": [
63+
"[concat('Microsoft.ServiceBus/namespaces/',
64+
parameters('serviceBusNamespaceName'))]",
65+
],
66+
"properties": {},
67+
"resources": []
68+
}
69+
]
70+
}
71+
```
72+
73+
74+
The sample is documented further inline in the [Program.cs](Program.cs) C# file.
75+
76+
[1]: https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-auto-forwarding

samples/DotNet/Microsoft.Azure.ServiceBus/BasicSendReceiveUsingQueueClient/BasicSendReceiveUsingQueueClient.csproj

-12
This file was deleted.

0 commit comments

Comments
 (0)