Service Bus for Windows Server 初用问题小结

简介: Service Bus 1.0 安装说明 中演示了Service Bus for Windows Server的安装过程,但是在使用过程中,Service Bus 也有一些注意事项,下文中会讲解几点 1.示例下载 在 http://servicebus.codeplex.com 中有Service Bus的使用示例,不过仅是Azure版本的。

Service Bus 1.0 安装说明 中演示了Service Bus for Windows Server的安装过程,但是在使用过程中,Service Bus 也有一些注意事项,下文中会讲解几点

1.示例下载

http://servicebus.codeplex.com 中有Service Bus的使用示例,不过仅是Azure版本的。

2.程序集引用

引用Microsoft.ServiceBus.dll可以在"X:\Program Files\Service Bus\1.0\Microsoft.ServiceBus.dll"找到,当然,也可以使用NuGet来获取Windows Azure Service Bus:

image

 

3.关于连接

Service Bus for Windows Server 在代码编写上的主要不同主要集中在ConnectionString的编写上.在Service Bus for Windows Azure中通常使用以下代码来进行NamespaceManager的构造:

   1:  TokenProvider credentials = TokenProvider.CreateSharedSecretTokenProvider(Sender.IssuerName, Sender.IssuerKey);
   2:  Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", Sender.ServiceNamespace, string.Empty);
   3:  NamespaceManager namespaceClient = new NamespaceManager(serviceUri, credentials);

不过在Service Bus for Windows Server 中,可以使用ServiceBusConnectionStringBuilder类来构造ConnectionString:

   1:  string ServerFQDN = "hostname";
   2:  int HttpPort = 9355;
   3:  int TcpPort = 9354;
   4:  string ServiceNamespace = "NameSpace";
   5:  ServiceBusConnectionStringBuilder connBuilder = new ServiceBusConnectionStringBuilder();
   6:  connBuilder.ManagementPort = HttpPort;
   7:  connBuilder.RuntimePort = TcpPort;
   8:  connBuilder.Endpoints.Add(new UriBuilder() {Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace}.Uri);
   9:  connBuilder.StsEndpoints.Add(new UriBuilder() {Scheme = "https", Host = ServerFQDN, Port = HttpPort, Path = ServiceNamespace}.Uri);
  10:  NamespaceManager namespaceClient = NamespaceManager.CreateFromConnectionString(connBuilder.ToString());

这样就可以连接到本地的ServiceBus服务并使用Queue及Topic了

3.远程访问

防火墙注意打开 9002-9004 9354-9356

并且NamespaceManager、MessagingFactory初始化时要指定TokenProvider

官司方文档中说可以通过证书或IssueUser来验证,但是我这里都没有尝试成功。只通过OAuth验证通过了。

   1:  var  tokenProvider = TokenProvider.CreateOAuthTokenProvider(
   2:                 new[] { new UriBuilder() { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace, Port = HttpPort }.Uri },
   3:                 new NetworkCredential("windows user", "windows user password"));
   4:   namespaceClient.Settings.TokenProvider = tokenProvider;

至于 MessagingFactory可以通过以下方法获得带有TokenProvider的实例

   1:  var runtimeAddress = string.Format("sb://{0}:{2}/{1}/", ServerFQDN, ServiceNamespace, TcpPort);
   2:  var factory = MessagingFactory.Create(runtimeAddress,
   3:                 new MessagingFactorySettings()
   4:                 {
   5:                     TokenProvider =  tokenProvider,
   6:                     OperationTimeout = TimeSpan.FromMinutes(30)
   7:                 });
目录
相关文章
|
26天前
|
运维 安全 网络安全
Windows Server 2019拨号“找不到设备”?Error 1058解决指南
Windows Server 2019拨号报错1058?别急!这不是硬件故障,而是关键服务被禁用。通过“服务依存关系”排查,依次启动“安全套接字隧道协议”“远程接入连接管理”和“路由与远程访问”服务,仅需4步即可恢复PPPoE或VPN拨号功能,轻松解决网络中断问题。
126 1
|
26天前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
658 3
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
|
29天前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
208 2
|
23天前
|
安全 Linux iOS开发
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
115 0
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
|
2月前
|
Linux 虚拟化 iOS开发
Windows Server 2025 OVF (2025 年 8 月更新) - VMware 虚拟机模板
Windows Server 2025 OVF (2025 年 8 月更新) - VMware 虚拟机模板
282 3
Windows Server 2025 OVF (2025 年 8 月更新) - VMware 虚拟机模板
|
2月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 8 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 8 月更新)
588 3
Windows Server 2022 中文版、英文版下载 (2025 年 8 月更新)
|
3月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 7 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 7 月更新)
430 0
Windows Server 2022 中文版、英文版下载 (2025 年 7 月更新)
|
3月前
|
安全 Cloud Native 数据中心
Windows Server 2019 中文版、英文版下载 (2025 年 7 月更新)
Windows Server 2019 中文版、英文版下载 (2025 年 7 月更新)
360 2
|
Linux 虚拟化 iOS开发
Windows Server 2025 OVF (2025 年 6 月更新) - VMware 虚拟机模板
Windows Server 2025 OVF (2025 年 6 月更新) - VMware 虚拟机模板
279 0
下一篇
oss教程