forked from Azure/azure-functions-host
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ServiceBus output binding support + sample
- Loading branch information
Showing
16 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"bindings": { | ||
"input": [ | ||
{ | ||
"type": "serviceBusTrigger", | ||
"name": "message", | ||
"queueName": "samples-input" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"type": "serviceBus", | ||
"name": "message", | ||
"queueName": "samples-input" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = function (context) { | ||
var message = context.message; | ||
context.log("Node.js ServiceBus queue trigger function processed message '" + JSON.stringify(message) + "'"); | ||
|
||
if (message.count < 1) | ||
{ | ||
// write a message back to the queue that this function is triggered on | ||
// ensuring that we only loop on this once | ||
message.count += 1; | ||
context.output({ | ||
message: JSON.stringify(message) | ||
}); | ||
} | ||
|
||
context.done(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Host.Bindings.Path; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script | ||
{ | ||
internal class ServiceBusBinding : Binding | ||
{ | ||
private readonly BindingTemplate _queueOrTopicNameBindingTemplate; | ||
|
||
public ServiceBusBinding(JobHostConfiguration config, string name, string queueOrTopicName, FileAccess fileAccess, bool isTrigger) : base(config, name, "serviceBus", fileAccess, isTrigger) | ||
{ | ||
QueueOrTopicName = queueOrTopicName; | ||
_queueOrTopicNameBindingTemplate = BindingTemplate.FromString(QueueOrTopicName); | ||
} | ||
|
||
public string QueueOrTopicName { get; private set; } | ||
|
||
public override bool HasBindingParameters | ||
{ | ||
get | ||
{ | ||
return _queueOrTopicNameBindingTemplate.ParameterNames.Any(); | ||
} | ||
} | ||
|
||
public override async Task BindAsync(IBinder binder, Stream stream, IReadOnlyDictionary<string, string> bindingData) | ||
{ | ||
string boundQueueName = QueueOrTopicName; | ||
if (bindingData != null) | ||
{ | ||
boundQueueName = _queueOrTopicNameBindingTemplate.Bind(bindingData); | ||
} | ||
|
||
boundQueueName = Resolve(boundQueueName); | ||
|
||
// only an output binding is supported | ||
using (StreamReader reader = new StreamReader(stream)) | ||
{ | ||
// TODO: only string supported currently - need to support other types | ||
IAsyncCollector<string> collector = binder.Bind<IAsyncCollector<string>>(new ServiceBusAttribute(boundQueueName)); | ||
string data = reader.ReadToEnd(); | ||
await collector.AddAsync(data); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ module.exports = function (context) { | |
|
||
context.output({ | ||
output: json | ||
}) | ||
}); | ||
|
||
context.done(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters