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

Commit 960f9da

Browse files
authored
Merge pull request #249 from Azure/dev
Merge Dev branch into master for 1.0.0-RC1 release
2 parents f70720e + 9128c42 commit 960f9da

File tree

97 files changed

+1401
-439
lines changed

Some content is hidden

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

97 files changed

+1401
-439
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
## Description
2-
<!--
3-
Please add an informative description that covers the changes made by the pull request.
42

5-
If applicable, reference the bug/issue that this pull request fixes here.
6-
-->
3+
This following list is used to make sure that common guidelines for a pull request are followed.
74

8-
This checklist is used to make sure that common guidelines for a pull request are followed.
9-
10-
- [ ] **I have read the [contribution guidelines](./CONTRIBUTING.md).**
11-
- [ ] Title of the pull request is clear and informative.
12-
- [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR.
13-
- [ ] The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).
14-
- [ ] If applicable, the public code is properly documented.
15-
- [ ] Pull request includes test coverage for the included changes.
16-
- [ ] The code builds without any errors.
5+
- **Read the [contribution guidelines](./CONTRIBUTING.md).**
6+
- Make title of the pull request clear and informative.
7+
- Link to appropriate [issue](https://github.com/Azure/azure-service-bus-dotnet/issues).
8+
- Include test coverage for the changes.

.github/SUPPORT.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Support resources to check prior to raising issues
2+
3+
1. Azure Service Bus [samples](https://github.com/Azure/azure-service-bus/tree/master/samples)
4+
1. Already [resolved issues](https://github.com/Azure/azure-service-bus-dotnet/issues?q=is%3Aissue+is%3Aclosed)
5+
1. [StackOverflow](https://stackoverflow.com/questions/tagged/azureservicebus)

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p align="center">
1+
<p align="center">
22
<img src="service-bus.png" alt="Microsoft Azure Relay" width="100"/>
33
</p>
44

@@ -8,8 +8,8 @@
88

99
|Build/Package|Status|
1010
|------|-------------|
11-
|master|[![Build status](https://ci.appveyor.com/api/projects/status/anpaipqto58ka5lk/branch/master?svg=true)](https://ci.appveyor.com/project/vinaysurya/azure-service-bus-dotnet/branch/master) [![codecov](https://codecov.io/gh/Azure/azure-service-bus-dotnet/branch/master/graph/badge.svg)](https://codecov.io/gh/Azure/azure-service-bus-dotnet)|
12-
|dev|[![Build status](https://ci.appveyor.com/api/projects/status/anpaipqto58ka5lk/branch/master?svg=true)](https://ci.appveyor.com/project/vinaysurya/azure-service-bus-dotnet/branch/dev) [![codecov](https://codecov.io/gh/Azure/azure-service-bus-dotnet/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-service-bus-dotnet)|
11+
|master|[![Build status](https://ci.appveyor.com/api/projects/status/o4kaqt06h62d0ugp/branch/master?svg=true)](https://ci.appveyor.com/project/vinaysurya/azure-service-bus-dotnet/branch/master) [![codecov](https://codecov.io/gh/Azure/azure-service-bus-dotnet/branch/master/graph/badge.svg)](https://codecov.io/gh/Azure/azure-service-bus-dotnet)|
12+
|dev|[![Build status](https://ci.appveyor.com/api/projects/status/o4kaqt06h62d0ugp/branch/dev?svg=true)](https://ci.appveyor.com/project/vinaysurya/azure-service-bus-dotnet/branch/dev) [![codecov](https://codecov.io/gh/Azure/azure-service-bus-dotnet/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-service-bus-dotnet)|
1313
|Microsoft.Azure.ServiceBus|[![NuGet Version and Downloads count](https://buildstats.info/nuget/Microsoft.Azure.ServiceBus?includePreReleases=true)](https://www.nuget.org/packages/Microsoft.Azure.ServiceBus/)|
1414

1515
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:
@@ -26,6 +26,10 @@ This library is built using .NET Standard 1.3. For more information on what plat
2626

2727
See our [Contribution Guidelines](./.github/CONTRIBUTING.md).
2828

29+
## How to get support
30+
31+
See our [Support Guidelines](./.github/SUPPORT.md)
32+
2933
## FAQ
3034

3135
### Where can I find examples that use this library?
@@ -36,7 +40,7 @@ See our [Contribution Guidelines](./.github/CONTRIBUTING.md).
3640

3741
In order to run the unit tests, you will need to do the following:
3842

39-
1. Deploy the Azure Resource Manager template located at [/build/azuredeploy.json](/templates/azuredeploy.json) by clicking the following button:
43+
1. Deploy the Azure Resource Manager template located at [/build/azuredeploy.json](/build/azuredeploy.json) by clicking the following button:
4044

4145
<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-service-bus-dotnet%2Fmaster%2Fbuild%2Fazuredeploy.json" target="_blank">
4246
<img src="http://azuredeploy.net/deploybutton.png"/>

src/Microsoft.Azure.ServiceBus/Amqp/AmqpExceptionHelper.cs

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using Microsoft.Azure.ServiceBus.Primitives;
5-
64
namespace Microsoft.Azure.ServiceBus.Amqp
75
{
86
using System;
@@ -82,7 +80,7 @@ public static Exception ToMessagingContractException(this AmqpMessage responseMe
8280
return exception;
8381
}
8482

85-
public static Exception ToMessagingContractException(Error error, bool connectionError = false)
83+
public static Exception ToMessagingContractException(this Error error, bool connectionError = false)
8684
{
8785
if (error == null)
8886
{
@@ -92,7 +90,7 @@ public static Exception ToMessagingContractException(Error error, bool connectio
9290
return ToMessagingContractException(error.Condition.Value, error.Description, connectionError);
9391
}
9492

95-
public static Exception ToMessagingContractException(string condition, string message, bool connectionError = false)
93+
static Exception ToMessagingContractException(string condition, string message, bool connectionError = false)
9694
{
9795
if (string.Equals(condition, AmqpClientConstants.TimeoutError.Value))
9896
{
@@ -162,12 +160,7 @@ public static Exception ToMessagingContractException(string condition, string me
162160
return new ServiceBusException(true, message);
163161
}
164162

165-
public static Exception GetClientException(Exception exception)
166-
{
167-
return GetClientException(exception, null);
168-
}
169-
170-
public static Exception GetClientException(Exception exception, string referenceId)
163+
public static Exception GetClientException(Exception exception, string referenceId = null, Exception innerException = null)
171164
{
172165
StringBuilder builder = new StringBuilder();
173166
builder.AppendFormat(CultureInfo.InvariantCulture, exception.Message);
@@ -177,27 +170,36 @@ public static Exception GetClientException(Exception exception, string reference
177170
}
178171

179172
string message = builder.ToString();
173+
var aggregateException = innerException == null ? exception : new AggregateException(exception, innerException);
180174

181175
switch (exception)
182176
{
183177
case SocketException _:
178+
message = builder.AppendFormat(CultureInfo.InvariantCulture, $" ErrorCode: {((SocketException)exception).SocketErrorCode}").ToString();
179+
return new ServiceBusCommunicationException(message, aggregateException);
180+
184181
case IOException _:
185-
return new ServiceBusCommunicationException(message, exception);
182+
var socketException = exception.InnerException as SocketException;
183+
if (socketException != null)
184+
{
185+
message = builder.AppendFormat(CultureInfo.InvariantCulture, $" ErrorCode: {socketException.SocketErrorCode}").ToString();
186+
}
187+
return new ServiceBusCommunicationException(message, aggregateException);
186188

187189
case AmqpException amqpException:
188-
return ToMessagingContractException(amqpException.Error);
190+
return amqpException.Error.ToMessagingContractException();
189191

190192
case OperationCanceledException operationCanceledException when operationCanceledException.InnerException is AmqpException amqpException:
191-
return ToMessagingContractException(amqpException.Error);
193+
return amqpException.Error.ToMessagingContractException();
192194

193195
case OperationCanceledException _:
194-
return new ServiceBusException(true, message, exception);
196+
return new ServiceBusException(true, message, aggregateException);
195197

196198
case TimeoutException _:
197-
return new ServiceBusTimeoutException(message, exception);
199+
return new ServiceBusTimeoutException(message, aggregateException);
198200
}
199201

200-
return exception;
202+
return aggregateException;
201203
}
202204

203205
public static string GetTrackingId(this AmqpLink link)
@@ -211,5 +213,29 @@ public static string GetTrackingId(this AmqpLink link)
211213

212214
return null;
213215
}
216+
217+
public static Exception GetInnerException(this AmqpObject amqpObject)
218+
{
219+
Exception innerException;
220+
switch (amqpObject)
221+
{
222+
case AmqpSession amqpSession:
223+
innerException = amqpSession.TerminalException ?? amqpSession.Connection.TerminalException;
224+
break;
225+
226+
case AmqpLink amqpLink:
227+
innerException = amqpLink.TerminalException ?? amqpLink.Session.TerminalException ?? amqpLink.Session.Connection.TerminalException;
228+
break;
229+
230+
case RequestResponseAmqpLink amqpReqRespLink:
231+
innerException = amqpReqRespLink.TerminalException ?? amqpReqRespLink.Session.TerminalException ?? amqpReqRespLink.Session.Connection.TerminalException;
232+
break;
233+
234+
default:
235+
return null;
236+
}
237+
238+
return innerException == null ? null : GetClientException(innerException);
239+
}
214240
}
215241
}

src/Microsoft.Azure.ServiceBus/Amqp/AmqpLinkCreator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Microsoft.Azure.ServiceBus.Amqp
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Amqp;
99
using Microsoft.Azure.Amqp.Framing;
10+
using Microsoft.Azure.ServiceBus.Primitives;
1011

1112
internal abstract class AmqpLinkCreator
1213
{
@@ -58,13 +59,14 @@ public async Task<AmqpObject> CreateAndOpenAmqpLinkAsync()
5859
{
5960
MessagingEventSource.Log.AmqpSessionCreationException(this.entityPath, connection, exception);
6061
session?.Abort();
61-
throw;
62+
throw AmqpExceptionHelper.GetClientException(exception, null, session.GetInnerException());
6263
}
6364

65+
AmqpObject link = null;
6466
try
6567
{
6668
// Create Link
67-
AmqpObject link = this.OnCreateAmqpLink(connection, this.amqpLinkSettings, session);
69+
link = this.OnCreateAmqpLink(connection, this.amqpLinkSettings, session);
6870
await link.OpenAsync(timeoutHelper.RemainingTime()).ConfigureAwait(false);
6971
return link;
7072
}
@@ -76,7 +78,7 @@ public async Task<AmqpObject> CreateAndOpenAmqpLinkAsync()
7678
connection,
7779
exception);
7880

79-
throw;
81+
throw AmqpExceptionHelper.GetClientException(exception, null, link?.GetInnerException());
8082
}
8183
}
8284

src/Microsoft.Azure.ServiceBus/Amqp/AmqpMessageConverter.cs

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ namespace Microsoft.Azure.ServiceBus.Amqp
88
using System.Collections.Generic;
99
using System.IO;
1010
using System.Runtime.Serialization;
11-
using Microsoft.Azure.Amqp;
12-
using Microsoft.Azure.Amqp.Encoding;
13-
using Microsoft.Azure.Amqp.Framing;
14-
using Microsoft.Azure.ServiceBus.Filters;
15-
using SBMessage = Microsoft.Azure.ServiceBus.Message;
11+
using Azure.Amqp;
12+
using Azure.Amqp.Encoding;
13+
using Azure.Amqp.Framing;
14+
using Framing;
15+
using Primitives;
16+
using SBMessage = Message;
1617

1718
static class AmqpMessageConverter
1819
{
@@ -357,10 +358,96 @@ public static AmqpMap GetRuleDescriptionMap(RuleDescription description)
357358

358359
AmqpMap amqpAction = GetRuleActionMap(description.Action as SqlRuleAction);
359360
ruleDescriptionMap[ManagementConstants.Properties.SqlRuleAction] = amqpAction;
361+
ruleDescriptionMap[ManagementConstants.Properties.RuleName] = description.Name;
360362

361363
return ruleDescriptionMap;
362364
}
363365

366+
public static RuleDescription GetRuleDescription(AmqpRuleDescriptionCodec amqpDescription)
367+
{
368+
Filter filter = GetFilter(amqpDescription.Filter);
369+
RuleAction action = GetRuleAction(amqpDescription.Action);
370+
371+
RuleDescription description = new RuleDescription(filter)
372+
{
373+
Action = action,
374+
Name = amqpDescription.RuleName
375+
};
376+
377+
return description;
378+
}
379+
380+
public static Filter GetFilter(AmqpFilterCodec amqpFilter)
381+
{
382+
Filter filter;
383+
384+
switch (amqpFilter.DescriptorCode)
385+
{
386+
case AmqpSqlFilterCodec.Code:
387+
var amqpSqlFilter = (AmqpSqlFilterCodec)amqpFilter;
388+
filter = new SqlFilter(amqpSqlFilter.Expression);
389+
break;
390+
391+
case AmqpTrueFilterCodec.Code:
392+
filter = new TrueFilter();
393+
break;
394+
395+
case AmqpFalseFilterCodec.Code:
396+
filter = new FalseFilter();
397+
break;
398+
399+
case AmqpCorrelationFilterCodec.Code:
400+
var amqpCorrelationFilter = (AmqpCorrelationFilterCodec)amqpFilter;
401+
var correlationFilter = new CorrelationFilter()
402+
{
403+
CorrelationId = amqpCorrelationFilter.CorrelationId,
404+
MessageId = amqpCorrelationFilter.MessageId,
405+
To = amqpCorrelationFilter.To,
406+
ReplyTo = amqpCorrelationFilter.ReplyTo,
407+
Label = amqpCorrelationFilter.Label,
408+
SessionId = amqpCorrelationFilter.SessionId,
409+
ReplyToSessionId = amqpCorrelationFilter.ReplyToSessionId,
410+
ContentType = amqpCorrelationFilter.ContentType
411+
};
412+
413+
foreach (var property in amqpCorrelationFilter.Properties)
414+
{
415+
correlationFilter.Properties.Add(property.Key.Key.ToString(), property.Value);
416+
}
417+
418+
filter = correlationFilter;
419+
break;
420+
421+
default:
422+
throw new NotSupportedException($"Unknown filter descriptor code: {amqpFilter.DescriptorCode}");
423+
}
424+
425+
return filter;
426+
}
427+
428+
static RuleAction GetRuleAction(AmqpRuleActionCodec amqpAction)
429+
{
430+
RuleAction action;
431+
432+
if (amqpAction.DescriptorCode == AmqpEmptyRuleActionCodec.Code)
433+
{
434+
action = null;
435+
}
436+
else if (amqpAction.DescriptorCode == AmqpSqlRuleActionCodec.Code)
437+
{
438+
AmqpSqlRuleActionCodec amqpSqlAction = (AmqpSqlRuleActionCodec)amqpAction;
439+
SqlRuleAction sqlAction = new SqlRuleAction(amqpSqlAction.SqlExpression);
440+
441+
action = sqlAction;
442+
}
443+
else
444+
{
445+
throw new NotSupportedException($"Unknown action descriptor code: {amqpAction.DescriptorCode}");
446+
}
447+
448+
return action;
449+
}
450+
364451
static bool TryGetAmqpObjectFromNetObject(object netObject, MappingType mappingType, out object amqpObject)
365452
{
366453
amqpObject = null;
@@ -585,7 +672,7 @@ static AmqpMap GetCorrelationFilterMap(CorrelationFilter correlationFilter)
585672

586673
return correlationFilterMap;
587674
}
588-
675+
589676
static AmqpMap GetRuleActionMap(SqlRuleAction sqlRuleAction)
590677
{
591678
AmqpMap ruleActionMap = null;

src/Microsoft.Azure.ServiceBus/Amqp/AmqpRequestResponseLinkCreator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Microsoft.Azure.ServiceBus.Amqp
55
{
66
using Microsoft.Azure.Amqp;
7+
using Microsoft.Azure.ServiceBus.Primitives;
78

89
internal class AmqpRequestResponseLinkCreator : AmqpLinkCreator
910
{

src/Microsoft.Azure.ServiceBus/Amqp/AmqpSendReceiveLinkCreator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Microsoft.Azure.ServiceBus.Amqp
55
{
66
using Microsoft.Azure.Amqp;
7+
using Microsoft.Azure.ServiceBus.Primitives;
78

89
internal class AmqpSendReceiveLinkCreator : AmqpLinkCreator
910
{

0 commit comments

Comments
 (0)