This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
Functions.cs
78 lines (68 loc) · 2.91 KB
/
Functions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.ServiceBus.Messaging;
namespace ServiceBus
{
public class Functions
{
private const string PrefixForAll = "s-";
private const string QueueNamePrefix = PrefixForAll + "queue-";
private const string TopicName = PrefixForAll + "topic";
public const string StartQueueName = QueueNamePrefix + "start";
// Passes a service bus message from a queue to another queue using strings
public static void SBQueue2SBQueue(
[ServiceBusTrigger(StartQueueName)] string start,
[ServiceBus(QueueNamePrefix + "1")] out string message,
TextWriter log)
{
message = start + "-SBQueue2SBQueue";
log.WriteLine("SBQueue2SBQueue: " + message);
}
// Passes a service bus message from a queue to topic using a brokered message
public static void SBQueue2SBTopic(
[ServiceBusTrigger(QueueNamePrefix + "1")] string message,
[ServiceBus(TopicName)] out BrokeredMessage output,
TextWriter log)
{
message = message + "-SBQueue2SBTopic";
Stream stream = new MemoryStream();
TextWriter writer = new StreamWriter(stream);
writer.Write(message);
writer.Flush();
stream.Position = 0;
output = new BrokeredMessage(stream)
{
ContentType = "text/plain"
};
log.WriteLine("SBQueue2SBTopic: " + message);
}
// Topic subscription listener #1
public static void SBTopicListener1(
[ServiceBusTrigger(TopicName, QueueNamePrefix + "topic-1")] string message,
TextWriter log)
{
log.WriteLine("SBTopicListener1: " + message);
}
// Topic subscription listener #2
public static void SBTopicListener2(
[ServiceBusTrigger(TopicName, QueueNamePrefix + "topic-2")] BrokeredMessage message,
TextWriter log)
{
using (Stream stream = message.GetBody<Stream>())
using (TextReader reader = new StreamReader(stream))
{
log.WriteLine("SBTopicListener2" + reader.ReadToEnd());
}
}
/// Demonstrates how AccessRights can be explicitly specified for queues/topics that
/// you don't have Manage rights too. If the queues/topics this function is operating on
/// don't already exist, an exception will be thrown, whereas the default behavior
/// assumes Manage and will attempt to create queues/topics if they don't exist.
public static void LimitedAccessExample(
[ServiceBusTrigger(StartQueueName, AccessRights.Listen)] string start,
[ServiceBus(QueueNamePrefix + "1", AccessRights.Send)] out string message)
{
message = start + "-SBQueue2SBQueue";
}
}
}