此默认设置为60秒,但我需要将其调整为30.我通过执行以下操作创建所有消息:
public void SendMessage<T>(T message)
{
string conn = "Microsoft.ServiceBus.ConnectionString." + message.GetType().Name;
string queueName = ConfigurationManager.AppSettings[message.GetType().Name + "QueueName"];
string connectionString = ConfigurationManager.AppSettings[conn];
QueueClient Client = QueueClient.CreateFromConnectionString(connectionString, queueName);
var m = new BrokeredMessage();
m.Properties["body"] = JsonConvert.SerializeObject(message);
Client.Send(m);
}
在这里我可以设置向ServiceBus发送消息的超时时间吗?目前服务总线已关闭,所以这导致我真正的问题:(
答案 0 :(得分:4)
您可以使用MessagingFactorySettings更改超时:
Uri serviceBusUri = ServiceBusEnvironment.CreateServiceUri("sb", "[serviceNamespace]", string.Empty);
MessagingFactorySettings factorySettings = new MessagingFactorySettings()
{
TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("[keyName]", "[sharedAccessKey]"),
OperationTimeout = TimeSpan.FromSeconds(30),
};
MessagingFactory messagingFactory = MessagingFactory.Create(serviceBusUri, factorySettings);
QueueClient Client = messagingFactory.CreateQueueClient("[QueueName]");