您现在访问的是微软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

java 总线_用于 Java 的服务总线库相关推荐

  1. java建立_利用Java创建Windows服务

    1.Java测试代码 importorg.apache.log4j.Logger;public classTest {private static Logger logger = Logger.get ...

  2. 易语言 java支持_开源Java客户端可以连接易语言服务器

    我们的服务端处理客户端的连接请求是同步进行的, 每次接收到来自客户端的连接请求后, 都要先跟当前的客户端通信完之后才能再处理下一个连接请求. 这在并发比较多的情况下会严重影响程序的性能, 为此,我们可 ...

  3. 尚学堂java培训_送给 Java 自学者或者初学者的最全知识清单,2020 年 Java 就该这么学...

    最近逛知乎,发现有很多想自学 Java 或者 Java 初学者提问,不知道如何学习 Java?我接触 Java 快 8 年的时间了,一直从事 Java 开发工作,自己一直升级打怪,对于如何更好的学习 ...

  4. java安装_使用Java 9模块化来发布零依赖本机应用程序

    java安装 为什么我不能仅构建一个.EXE? 首次引入Java时,主流编程语言大多要么编译成独立的可执行文件(例如C / C ++,COBOL),要么在解释器中运行(例如Perl,Tcl). 对于许 ...

  5. java转账_使用Java模拟银行账户存、取款、转账功能

    半枯 package bank;import java.util.Scanner;/** * 1.建立一个银行账户类(Acount),具有建立新帐号.查询余额.存款.取款.转账 * 即从本账户把钱转给 ...

  6. python能解密java的_实现Java加密,Python解密的RSA非对称加密算法功能

    摘要 因为最近业务需要使用到openssl的rsa非对称加密算法,研究了下它的使用方式,但是特殊在于前端分IOS和android两端,所以前端部门要求使用java给他们做一个加密工具包,但是因为服务端 ...

  7. java掌握_掌握Java 11的Constantdynamic

    java掌握 为了使JVM对动态语言更具吸引力,该平台的第七版已将invokedynamic引入了其指令集. Java开发人员通常不会注意到此功能,因为该功能已隐藏在Java字节码中. 简而言之,通过 ...

  8. java常见_关于Java的常见误解

    java常见 Java是世界上使用最广泛的语言(需要引用),每个人对此都有自己的见解. 由于它是主流,所以通常会嘲笑它,有时是对的,但有时批评并没有触及现实. 我将尝试解释我最喜欢的5个关于Java的 ...

  9. 虚拟机 java 开发_深入浅出 Java 虚拟机 · 通往高级 Java 开发的必经之路

    第一章 JVM 内存模型 Java 虚拟机(Java Virtual Machine=JVM)的内存空间分为五个部分,分别是:程序计数器 Java 虚拟机栈 本地方法栈 堆 方法区. 下面对这五个区域 ...

  10. java编译_解析 Java 即时编译器原理。

    ↑ 点击上面 "时代Java"关注我们,关注新技术,学习新知识! 一.导读 常见的编译型语言如C++,通常会把代码直接编译成CPU所能理解的机器码来运行.而Java为了实现&quo ...

最新文章

  1. RedHat6.5网卡问题总结
  2. 图神经网络的二阶池化:从节点表示中学习图的表示
  3. boost::geometry::sym_difference用法的测试程序
  4. sqlserver 的一些好用的插件
  5. msf aux模块使用
  6. Radar Installation
  7. c++从字符串中提取数字求和_【函数应用】单元格文本内提取数字并求和
  8. 十五、Python操作mysql数据库
  9. 25-60k/m | 湃道智能招聘
  10. UltraEdit 所有快捷键 说明
  11. 2018年华尔街高盛、花旗等投行业绩创新高!
  12. 了解J1939协议和J1939数据记录仪(车辆工程机械中的黑匣子)
  13. 十八、D触发器介绍:
  14. js日期格式化的两种方法
  15. 人类HUMANKIND怎么攻城?攻城战准备与打法教程
  16. 2021牛客多校6 I Intervals on the Ring
  17. 创维广电服务器无线,创维酷开电视连接有线和无线上网教程
  18. uniapp中uni.navigateTo传递变量
  19. 免费不限速不限存储的网盘推荐
  20. springboot毕设项目电子竞技赛事管理系统f1v55(java+VUE+Mybatis+Maven+Mysql)

热门文章

  1. 如何快速提高产品互动能力?
  2. EI 和 SCI 检索号查询
  3. ArcGIS动态表格扩展模块Mapping and Charting Solutions使用教程及下载地址
  4. [CEOI2017]Mousetrap
  5. IntelliJ IDEA 2017 提示“Unmapped Spring configuration files found.Please configure Spring facet.”
  6. 测试方案包括哪些内容
  7. C盘清理 / 磁盘清理
  8. 计算机程序有哪些性质,程序的特性有哪些
  9. 苹果CMSv10系统标签,仿站必备
  10. 电脑重装系统后谷歌浏览器连不上网的解决方案