Sharepoint 列表中的项目发生更改时向 Azure ServiceBus 发送消息
Send message to Azure ServiceBus when items have changed in a Sharepoint List
我想在 SharePoint 列表中的某些项目发生更改时将消息发送到 Azure ServiceBus 队列。当您 upload/delete 一个文件时,我需要创建一个事件,使用文件的内容和 ID 在 Azure 服务总线中排队消息。我不知道如何创建这样的活动,有人可以指点我一些文章,开始教程。
您正在寻找事件接收者:
By creating event receivers, you can respond when a user interacts with SharePoint items such as lists or list items. For example, the code in an event receiver can be triggered when a user changes the calendar or deletes a name from a contacts list.
文档中的示例代码:
public override void ItemAdded(SPItemEventProperties properties)
{
properties.ListItem["Patient Name"] = "Scott Brown";
properties.ListItem.Update();
base.ItemAdded(properties);
}
现在您需要更改此代码以将消息发送到服务总线队列:
Get started with Service Bus Queues
public override void ItemAdded(SPItemEventProperties properties)
{
var connectionString = "<Your connection string>";
var queueName = "<Your queue name>";
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
var message = new BrokeredMessage("This is a test message!");
client.Send(message);
base.ItemAdded(properties);
}
如果您需要发送文件内容,请记住以下几点:
Service Bus queues support a maximum message size of 256 Kb (the header, which includes the standard and custom application properties, can have a maximum size of 64 Kb).
所以您可能需要将您的文件存储到 blob 存储中,并且只需向队列发送一条消息,其中还包含创建 blob 的 ID。
我想在 SharePoint 列表中的某些项目发生更改时将消息发送到 Azure ServiceBus 队列。当您 upload/delete 一个文件时,我需要创建一个事件,使用文件的内容和 ID 在 Azure 服务总线中排队消息。我不知道如何创建这样的活动,有人可以指点我一些文章,开始教程。
您正在寻找事件接收者:
By creating event receivers, you can respond when a user interacts with SharePoint items such as lists or list items. For example, the code in an event receiver can be triggered when a user changes the calendar or deletes a name from a contacts list.
文档中的示例代码:
public override void ItemAdded(SPItemEventProperties properties)
{
properties.ListItem["Patient Name"] = "Scott Brown";
properties.ListItem.Update();
base.ItemAdded(properties);
}
现在您需要更改此代码以将消息发送到服务总线队列: Get started with Service Bus Queues
public override void ItemAdded(SPItemEventProperties properties)
{
var connectionString = "<Your connection string>";
var queueName = "<Your queue name>";
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
var message = new BrokeredMessage("This is a test message!");
client.Send(message);
base.ItemAdded(properties);
}
如果您需要发送文件内容,请记住以下几点:
Service Bus queues support a maximum message size of 256 Kb (the header, which includes the standard and custom application properties, can have a maximum size of 64 Kb).
所以您可能需要将您的文件存储到 blob 存储中,并且只需向队列发送一条消息,其中还包含创建 blob 的 ID。