Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 10d8c1b

Browse files
authored
Merge pull request #111 from Azure/dev
0.0.2-preview release
2 parents b6f0474 + 9754784 commit 10d8c1b

File tree

99 files changed

+5906
-3441
lines changed

Some content is hidden

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

99 files changed

+5906
-3441
lines changed

README.md

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66

77
**Please be aware that this library is currently in active development, and is not intended for production**
88

9-
[![Build status](https://ci.appveyor.com/api/projects/status/anpaipqto58ka5lk/branch/master?svg=true)](https://ci.appveyor.com/project/jtaubensee/azure-service-bus-dotnet/branch/master)
9+
|Build/Package|Status|
10+
|------|-------------|
11+
|master|[![Build status](https://ci.appveyor.com/api/projects/status/anpaipqto58ka5lk/branch/master?svg=true)](https://ci.appveyor.com/project/jtaubensee/azure-service-bus-dotnet/branch/master)|
12+
|dev|[![Build status](https://ci.appveyor.com/api/projects/status/anpaipqto58ka5lk/branch/master?svg=true)](https://ci.appveyor.com/project/jtaubensee/azure-service-bus-dotnet/branch/dev)|
1013

1114
This is the next generation Service Bus .NET client library that focuses on queues & topics. If you are looking for Event Hubs and Relay clients, follow the below links:
1215
* [Event Hubs](https://github.com/azure/azure-event-hubs-dotnet)
1316
* [Relay](https://github.com/azure/azure-relay-dotnet)
14-
15-
For information on the current set of implemented features and features to come, see our [Road map](#road-map).
1617

17-
Azure Service Bus Messaging is an asynchronous messaging cloud platform that enables you to send messages between decoupled systems. Microsoft offers this feature as a service, which means that you do not need to host any of your own hardware in order to use it.
18+
Azure Service Bus is an asynchronous messaging cloud platform that enables you to send messages between decoupled systems. Microsoft offers this feature as a service, which means that you do not need to host any of your own hardware in order to use it.
1819

1920
Refer to the [online documentation](https://azure.microsoft.com/services/service-bus/) to learn more about Service Bus.
2021

@@ -55,38 +56,3 @@ The standard way to manage Azure resources is by using [Azure Resource Manager](
5556
* GitHub repo - [https://github.com/Azure/azure-sdk-for-net/tree/AutoRest/src/ResourceManagement/ServiceBus](https://github.com/Azure/azure-sdk-for-net/tree/AutoRest/src/ResourceManagement/ServiceBus)
5657
* NuGet package - [https://www.nuget.org/packages/Microsoft.Azure.Management.ServiceBus/](https://www.nuget.org/packages/Microsoft.Azure.Management.ServiceBus/)
5758
* Sample - [https://github.com/Azure-Samples/service-bus-dotnet-management](https://github.com/Azure-Samples/service-bus-dotnet-management)
58-
59-
## Road map
60-
61-
- [x] Sprint 1: **Complete**
62-
63-
All runtime operations for queues (not topics / subscriptions)
64-
* Send
65-
* Receive/Peeklock (without receive by sequence number)
66-
* Abandon
67-
* Deadletter
68-
* Defer
69-
70-
- [x] Sprint 2: **Complete**
71-
* RenewLock (Request/Response)
72-
* Batch operation - Explicit batching only
73-
* Runtime operation only
74-
* Linux testing setup/investigation
75-
76-
- [x] Sprint 3: **Complete**
77-
* Add topic/subscription support
78-
* Session support
79-
* Accept session
80-
* Session Receive/ReceiveBatch
81-
82-
- [x] Sprint 4: **Complete**
83-
* Retry policy
84-
* Receive by sequence number
85-
86-
- [ ] Sprint 5: Early 2017
87-
* Add major error conditions (ex. preventing all operations that are not supported, for Ex Transaction scenarios, etc)
88-
* Request/Response features:
89-
* Add/Remove Rule
90-
* Browse messages and sessions
91-
* Scheduled messages specific API (Scheduling of messages can be done today through the queue/topic client, but this item is to add specific API's for scheduled messages)
92-
* OnMessage/OnSession handlers

samples/ReceiveSample/Program.cs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,54 @@
44
namespace ReceiveSample
55
{
66
using System;
7+
using System.Text;
78
using System.Threading.Tasks;
89
using Microsoft.Azure.ServiceBus;
910

1011
public class Program
1112
{
12-
private static QueueClient queueClient;
13+
private static IQueueClient queueClient;
1314
private const string ServiceBusConnectionString = "{Service Bus connection string}";
1415
private const string QueueName = "{Queue path/name}";
1516

1617
public static void Main(string[] args)
1718
{
18-
MainAsync(args).GetAwaiter().GetResult();
19+
MainAsync().GetAwaiter().GetResult();
1920
}
2021

21-
private static async Task MainAsync(string[] args)
22+
private static async Task MainAsync()
2223
{
23-
// Creates a ServiceBusConnectionStringBuilder object from the connection string, and sets the EntityPath.
24-
var connectionStringBuilder = new ServiceBusConnectionStringBuilder(ServiceBusConnectionString)
25-
{
26-
EntityPath = QueueName
27-
};
28-
29-
// Initializes the static QueueClient variable that will be used in the ReceiveMessages method.
30-
queueClient = QueueClient.CreateFromConnectionString(connectionStringBuilder.ToString());
24+
queueClient = new QueueClient(ServiceBusConnectionString, QueueName, ReceiveMode.PeekLock);
25+
ReceiveMessages();
3126

32-
await ReceiveMessages();
27+
Console.WriteLine("Press any key to stop receiving messages.");
28+
Console.ReadKey();
3329

3430
// Close the client after the ReceiveMessages method has exited.
3531
await queueClient.CloseAsync();
3632
}
3733

3834
// Receives messages from the queue in a loop
39-
private static async Task ReceiveMessages()
35+
private static void ReceiveMessages()
4036
{
41-
Console.WriteLine("Press ctrl-c to exit receive loop.");
42-
while (true)
37+
try
4338
{
44-
try
45-
{
46-
// Receive the next message from the queue
47-
var message = await queueClient.ReceiveAsync();
48-
49-
// Write the message body to the console
50-
Console.WriteLine($"Received message: {message.GetBody<string>()}");
51-
52-
// Complete the message so that it is not received again
53-
await message.CompleteAsync();
54-
}
55-
catch (Exception exception)
56-
{
57-
Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
58-
}
59-
60-
// Delay by 10 milliseconds so that the console can keep up
61-
await Task.Delay(10);
39+
// Register a OnMessage callback
40+
queueClient.RegisterMessageHandler(
41+
async (message, token) =>
42+
{
43+
// Process the message
44+
Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}");
45+
46+
// Complete the message so that it is not received again.
47+
// This can be done only if the queueClient is opened in ReceiveMode.PeekLock mode.
48+
await queueClient.CompleteAsync(message.SystemProperties.LockToken);
49+
},
50+
new RegisterHandlerOptions() {MaxConcurrentCalls = 1, AutoComplete = false});
51+
}
52+
catch (Exception exception)
53+
{
54+
Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
6255
}
6356
}
6457
}

samples/ReceiveSample/readme.md

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,24 @@ In this tutorial, we will write a console application to receive messages from a
5959
1. Create a new method called `ReceiveMessages` with the following code:
6060

6161
```csharp
62-
// Receives messages from the queue in a loop
63-
private static async Task ReceiveMessages()
62+
try
6463
{
65-
Console.WriteLine("Press ctrl-c to exit receive loop.");
66-
while (true)
67-
{
68-
try
64+
// Register a OnMessage callback
65+
queueClient.RegisterMessageHandler(
66+
async (message, token) =>
6967
{
70-
// Receive the next message from the queue
71-
var message = await queueClient.ReceiveAsync();
72-
73-
// Write the message body to the console
74-
Console.WriteLine($"Received message: {message.GetBody<string>()}");
75-
76-
// Complete the messgage so that it is not received again
77-
await message.CompleteAsync();
78-
}
79-
catch (Exception exception)
80-
{
81-
Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
82-
}
83-
84-
// Delay by 10 milliseconds so that the console can keep up
85-
await Task.Delay(10);
86-
}
68+
// Process the message
69+
Console.WriteLine($"Received message: SequenceNumber:{message.SequenceNumber} Body:{message.GetBody<string>()}");
70+
71+
// Complete the message so that it is not received again.
72+
// This can be done only if the queueClient is opened in ReceiveMode.PeekLock mode.
73+
await queueClient.CompleteAsync(message.LockToken);
74+
},
75+
new RegisterHandlerOptions() {MaxConcurrentCalls = 1, AutoComplete = false});
76+
}
77+
catch (Exception exception)
78+
{
79+
Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
8780
}
8881
```
8982

@@ -92,16 +85,11 @@ In this tutorial, we will write a console application to receive messages from a
9285
```csharp
9386
private static async Task MainAsync(string[] args)
9487
{
95-
// Creates a ServiceBusConnectionStringBuilder object from the connection string, and sets the EntityPath.
96-
var connectionStringBuilder = new ServiceBusConnectionStringBuilder(ServiceBusConnectionString)
97-
{
98-
EntityPath = QueueName
99-
};
100-
101-
// Initializes the static QueueClient variable that will be used in the ReceiveMessages method.
102-
queueClient = QueueClient.CreateFromConnectionString(connectionStringBuilder.ToString());
88+
queueClient = new QueueClient(ServiceBusConnectionString, QueueName, ReceiveMode.PeekLock);
89+
ReceiveMessages();
10390

104-
await ReceiveMessages();
91+
Console.WriteLine("Press any key to stop receiving messages.");
92+
Console.ReadKey();
10593

10694
// Close the client after the ReceiveMessages method has exited.
10795
await queueClient.CloseAsync();

samples/SendSample/Program.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
namespace SendSample
55
{
66
using System;
7+
using System.Text;
78
using System.Threading.Tasks;
89
using Microsoft.Azure.ServiceBus;
910

1011
public class Program
1112
{
12-
private static QueueClient queueClient;
13+
private static IQueueClient queueClient;
1314
private const string ServiceBusConnectionString = "{Service Bus connection string}";
1415
private const string QueueName = "{Queue path/name}";
1516

@@ -20,14 +21,7 @@ public static void Main(string[] args)
2021

2122
private static async Task MainAsync(string[] args)
2223
{
23-
// Creates a ServiceBusConnectionStringBuilder object from the connection string, and sets the EntityPath.
24-
var connectionStringBuilder = new ServiceBusConnectionStringBuilder(ServiceBusConnectionString)
25-
{
26-
EntityPath = QueueName
27-
};
28-
29-
// Initializes the static QueueClient variable that will be used in the ReceiveMessages method.
30-
queueClient = QueueClient.CreateFromConnectionString(connectionStringBuilder.ToString());
24+
queueClient = new QueueClient(ServiceBusConnectionString, QueueName, ReceiveMode.PeekLock);
3125

3226
await SendMessagesToQueue(10);
3327

@@ -46,10 +40,10 @@ private static async Task SendMessagesToQueue(int numMessagesToSend)
4640
try
4741
{
4842
// Create a new brokered message to send to the queue
49-
var message = new BrokeredMessage($"Message {i}");
43+
var message = new Message(Encoding.UTF8.GetBytes($"Message {i}"));
5044

5145
// Write the body of the message to the console
52-
Console.WriteLine($"Sending message: {message.GetBody<string>()}");
46+
Console.WriteLine($"Sending message: {Encoding.UTF8.GetString(message.Body)}");
5347

5448
// Send the message to the queue
5549
await queueClient.SendAsync(message);

samples/SendSample/readme.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ In this tutorial, we will write a console application to send messages to a Serv
6666
try
6767
{
6868
// Create a new brokered message to send to the queue
69-
var message = new BrokeredMessage($"Message {i}");
69+
var message = new Message($"Message {i}");
7070

7171
// Write the body of the message to the console
7272
Console.WriteLine($"Sending message: {message.GetBody<string>()}");
@@ -92,15 +92,7 @@ In this tutorial, we will write a console application to send messages to a Serv
9292
```csharp
9393
private static async Task MainAsync(string[] args)
9494
{
95-
// Creates a ServiceBusConnectionStringBuilder object from the connection string, and sets the EntityPath.
96-
var connectionStringBuilder = new ServiceBusConnectionStringBuilder(ServiceBusConnectionString)
97-
{
98-
EntityPath = QueueName
99-
};
100-
101-
// Initializes the static QueueClient variable that will be used in the ReceiveMessages method.
102-
queueClient = QueueClient.CreateFromConnectionString(connectionStringBuilder.ToString());
103-
95+
queueClient = new QueueClient(ServiceBusConnectionString, QueueName, ReceiveMode.PeekLock);
10496
await SendMessagesToQueue(10);
10597

10698
// Close the client after the ReceiveMessages method has exited.

0 commit comments

Comments
 (0)