以天蓝色存储收到的消息
Storing received message in azure
我在 C# 中有一个简单的消息发送器
public static async Task SendMessageToTopic(string serviceBusConnectionString, string topic, string message)
{
const int numberOfMessages = 10;
topicClient = new TopicClient(serviceBusConnectionString, topic);
Console.WriteLine("======================================================");
Console.WriteLine("Press ENTER key to exit after sending all the messages.");
Console.WriteLine("======================================================");
// Send messages.
await SendMessagesAsync(message);
}
static async Task SendMessagesAsync(string message)
{
try
{
var encodedMessage = new Message(Encoding.UTF8.GetBytes(message));
// Write the body of the message to the console.
Console.WriteLine($"Sending message: {encodedMessage}");
// Send the message to the topic.
await topicClient.SendAsync(encodedMessage);
}
catch (Exception exception)
{
Console.WriteLine($"{DateTime.Now} :: Exception: {exception.Message}");
}
}
在另一端,我有一个简单的接收器应用程序,一切正常。
现在我想将我的消息(例如,整数)存储到 Azure 存储中以便稍后绘制它们。我按照此处所述设置端点和路由 https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-store-data-in-azure-table-storage#verify-your-message-in-your-storage-container
但是看起来我的容器是空的(我用 Azure Storage Explorer 看)
我认为有一些事情需要澄清。服务总线可用作 Azure IoT 中心的附加终结点之一。 IoT 中心目前支持 Azure 存储容器、事件中心、服务总线队列和服务总线主题,因为额外 endpoints.IoT 中心需要写入访问权限或配置(通过 Azure 门户)这些服务端点才能使消息路由正常工作。有关如何 understand IoT Hub Endpoints and configure message routing with Azure IoT Hub 的更多信息,请参见此处。您设置的终结点用于 IoT 中心而不是服务总线。
服务总线本身不支持将接收到的消息路由到存储容器或其他端点。如果要存储接收到的服务总线消息,可以使用 Azure Service Bus bindings for Azure Functions.Azure Functions supports trigger and output bindings for Service Bus queues and topics. This blog 显示如何使用 Azure Functions 绑定在 运行 时间内动态路由队列。
用于服务总线主题触发器示例的 C#(run.csx):
#r "Microsoft.WindowsAzure.Storage"
using System;
using System.Configuration;
using System.Net;
using System.Text;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public static async Task Run(string mySbMsg, TraceWriter log)
{
log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
string connectionString="{storage acount connectionString}";
CloudStorageAccount storageAccount;
CloudBlobClient client;
CloudBlobContainer container;
CloudBlockBlob blob;
storageAccount = CloudStorageAccount.Parse(connectionString);
client = storageAccount.CreateCloudBlobClient();
container = client.GetContainerReference("container01");
await container.CreateIfNotExistsAsync();
blob = container.GetBlockBlobReference(DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".json");
blob.Properties.ContentType = "application/json";
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(mySbMsg)))
{
await blob.UploadFromStreamAsync(stream);
}
}
我在 C# 中有一个简单的消息发送器
public static async Task SendMessageToTopic(string serviceBusConnectionString, string topic, string message)
{
const int numberOfMessages = 10;
topicClient = new TopicClient(serviceBusConnectionString, topic);
Console.WriteLine("======================================================");
Console.WriteLine("Press ENTER key to exit after sending all the messages.");
Console.WriteLine("======================================================");
// Send messages.
await SendMessagesAsync(message);
}
static async Task SendMessagesAsync(string message)
{
try
{
var encodedMessage = new Message(Encoding.UTF8.GetBytes(message));
// Write the body of the message to the console.
Console.WriteLine($"Sending message: {encodedMessage}");
// Send the message to the topic.
await topicClient.SendAsync(encodedMessage);
}
catch (Exception exception)
{
Console.WriteLine($"{DateTime.Now} :: Exception: {exception.Message}");
}
}
在另一端,我有一个简单的接收器应用程序,一切正常。 现在我想将我的消息(例如,整数)存储到 Azure 存储中以便稍后绘制它们。我按照此处所述设置端点和路由 https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-store-data-in-azure-table-storage#verify-your-message-in-your-storage-container 但是看起来我的容器是空的(我用 Azure Storage Explorer 看)
我认为有一些事情需要澄清。服务总线可用作 Azure IoT 中心的附加终结点之一。 IoT 中心目前支持 Azure 存储容器、事件中心、服务总线队列和服务总线主题,因为额外 endpoints.IoT 中心需要写入访问权限或配置(通过 Azure 门户)这些服务端点才能使消息路由正常工作。有关如何 understand IoT Hub Endpoints and configure message routing with Azure IoT Hub 的更多信息,请参见此处。您设置的终结点用于 IoT 中心而不是服务总线。
服务总线本身不支持将接收到的消息路由到存储容器或其他端点。如果要存储接收到的服务总线消息,可以使用 Azure Service Bus bindings for Azure Functions.Azure Functions supports trigger and output bindings for Service Bus queues and topics. This blog 显示如何使用 Azure Functions 绑定在 运行 时间内动态路由队列。
用于服务总线主题触发器示例的 C#(run.csx):
#r "Microsoft.WindowsAzure.Storage"
using System;
using System.Configuration;
using System.Net;
using System.Text;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public static async Task Run(string mySbMsg, TraceWriter log)
{
log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
string connectionString="{storage acount connectionString}";
CloudStorageAccount storageAccount;
CloudBlobClient client;
CloudBlobContainer container;
CloudBlockBlob blob;
storageAccount = CloudStorageAccount.Parse(connectionString);
client = storageAccount.CreateCloudBlobClient();
container = client.GetContainerReference("container01");
await container.CreateIfNotExistsAsync();
blob = container.GetBlockBlobReference(DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".json");
blob.Properties.ContentType = "application/json";
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(mySbMsg)))
{
await blob.UploadFromStreamAsync(stream);
}
}