java 总线_用于 Java 的服务总线库

本文介绍了Azure Service Bus,一个提供高度可靠队列和发布/订阅主题的企业级事务消息传递服务。Service Bus支持AMQP 1.0和HTTPS,适合Java开发者,提供了官方客户端库和示例代码。文章还提到了Service Bus高级版的特性,如专用容量、可预测性能和较低的总体成本。
摘要由CSDN通过智能技术生成

您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 Java 的服务总线库Service Bus libraries for Java

07/11/2017

本文内容

概述Overview

服务总线是一个企业级的事务消息传送平台服务,提供高度可靠的队列和发布/订阅主题,并具有依序传送、会话、分区、计划、复杂订阅以及工作流和事务处理等高级功能。Service Bus is an enterprise-class, transactional messaging platform service that provides highly reliable queues and publish/subscribe topics with deep feature capabilities such as ordered delivery, sessions, partitioning, scheduling, complex subscriptions, as well as workflow and transaction handling.

服务总线的功能与传统的高端本地消息中转站相当,并且往往优于后者。The Service Bus feature capabilities are comparable and often exceed those of high-end, on-premises legacy message brokers. 可通过 AMQP 1.0、HTTPS 等基于标准的协议来使用服务总线功能,所有协议手势均有完备的阐述,从而可以实现广泛的互操作性。The Service Bus features are available via standards-based protocols like AMQP 1.0 and HTTPS and all protocol gestures are fully documented, allowing for broad interoperability.

服务总线高级版注重高度可用和可靠的持久消息传送,即使在大规模的本地数据中心部署中也能提供有竞争力的吞吐量性能,同时可以消除硬件选用和采购流程、部署规划和执行,以及漫长的性能优化会议。Focusing on highly available and reliable durable messaging, the Service Bus Premium provides competitive throughput performance even with substantial local datacenter deployments, but without hardware selection and acquisition processes, deployment planning and execution, and endless performance optimization sessions.

服务总线高级版是完全托管型的产品,它采用以容量为导向的简单定价模型为每个租户保留专用容量实现可预测的性能,同时与商用本地中转站相比,总体成本极低。Service Bus Premium is a fully managed offering with dedicated capacity reserved for each tenant that yields predictable performance with a simple, capacity-oriented pricing model and at extremely lower overall cost than commercial on-premises brokers. 对于许多客户而言,服务总线高级版可以取代眼下的专用本地消息传送群集,即使附加的工作负荷不在云中运行。For many customers, Service Bus Premium can replace dedicated on-premises messaging clusters today, even if the attached workloads do not run in the cloud.

在消息传送文档部分中详细了解服务总线的概念

对于 Java 开发人员而言,服务总线提供 Microsoft 支持的本机 API,服务总线还能与符合 AMQP 1.0 规范的库(例如 Apache Qpid Proton 的 JMS 提供程序)配合使用。For Java developers, Service Bus provides a Microsoft supported native API and Service Bus can also be used with AMQP 1.0 compliant libraries such as Apache Qpid Proton's JMS provider.

客户端库Client library

The official Service Bus client is available in source code form on GitHub and binaries and packaged sources are available on Maven Central.

示例代码存储库包含的示例用于演示:The sample code repository contains samples for:

向 Maven 项目的 pom.xml 文件中添加依赖项,以便在自己的项目中使用库。Add a dependency to your Maven project's pom.xml file to use the library in your own project. 根据需要指定版本。Specify the version as desired.

向 Maven pom.xml 文件中添加依赖项,以便在项目中使用客户端库。Add a dependency to your Maven pom.xml file to use the client library in your project.

com.microsoft.azure

azure-servicebus

1.0.0

public class BasicSendReceiveWithQueueClient {

// Connection String for the namespace can be obtained from the Azure portal under the

// 'Shared Access policies' section.

private static final String connectionString = "{connection string}";

private static final String queueName = "{queue name}";

private static IQueueClient queueClient;

private static int totalSend = 100;

private static int totalReceived = 0;

public static void main(String[] args) throws Exception {

Log.log("Starting BasicSendReceiveWithQueueClient sample");

// create client

Log.log("Create queue client.");

queueClient = new QueueClient(new ConnectionStringBuilder(connectionString, queueName), ReceiveMode.PeekLock);

// send and receive

queueClient.registerMessageHandler(new MessageHandler(queueClient), new MessageHandlerOptions(1, false, Duration.ofMinutes(1)));

for (int i = 0; i < totalSend; i++) {

int j = i;

Log.log("Sending message #%d.", j);

queueClient.sendAsync(new Message("" + i)).thenRunAsync(() -> { Log.log("Sent message #%d.", j);});

}

while(totalReceived != totalSend) {

Thread.sleep(1000);

}

Log.log("Received all messages, exiting the sample.");

Log.log("Closing queue client.");

queueClient.close();

}

static class MessageHandler implements IMessageHandler {

private IQueueClient client;

public MessageHandler(IQueueClient client) {

this.client = client;

}

@Override

public CompletableFuture onMessageAsync(IMessage iMessage) {

Log.log("Received message with sq#: %d and lock token: %s.", iMessage.getSequenceNumber(), iMessage.getLockToken());

return this.client.completeAsync(iMessage.getLockToken()).thenRunAsync(() -> {

Log.log("Completed message sq#: %d and locktoken: %s", iMessage.getSequenceNumber(), iMessage.getLockToken());

totalReceived++;

});

}

@Override

public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {

Log.log(exceptionPhase + "-" + throwable.getMessage());

}

}

}

管理 APIManagement API

使用管理 API 创建和管理命名空间、主题、队列与订阅。Create and manage namespaces, topics, queues, and subscriptions with the management API.

请查看下面的一些示例:Please find some examples here:

在项目中使用管理 API:

\Use the Management API in your project:

\

向 Maven pom.xml 文件中添加依赖项,以便在项目中使用管理 API。Add a dependency to your Maven pom.xml file to use the management API in your project.

com.microsoft.azure

azure-mgmt-servicebus

1.3.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值