Java 消息服务 (JMS) 2.0 实体(预览版)Java message service (JMS) 2.0 entities (Preview)

连接到 Azure 服务总线高级版并使用 Azure 服务总线 JMS 库的客户端应用程序可以利用以下实体。Client applications connecting to Azure Service Bus Premium and utilizing the Azure Service Bus JMS library can leverage the below entities.

队列Queues

JMS 中的队列在语义上与传统的服务总线队列类似。Queues in JMS are semantically comparable with the traditional Service Bus queues.

若要创建队列,请使用 JMSContext 类中的以下方法:To create a Queue, utilize the below methods in the JMSContext class -

Queue createQueue(String queueName)

主题Topics

JMS 中的主题在语义上与传统的服务总线主题类似。Topics in JMS are semantically comparable with the traditional Service Bus topics.

若要创建主题,请使用 JMSContext 类中的以下方法:To create a Topic, utilize the below methods in the JMSContext class -

Topic createTopic(String topicName)

临时队列Temporary queues

当客户端应用程序需要在应用程序的生存期内存在的临时实体时,它可以使用临时队列。When a client application requires a temporary entity that exists for the lifetime of the application, it can use Temporary queues. 这些队列以请求-回复模式使用。These are utilized in the Request-Reply pattern.

若要创建临时队列,请使用 JMSContext 类中的以下方法:To create a temporary queue, utilize the below methods in the JMSContext class -

TemporaryQueue createTemporaryQueue()

临时主题Temporary topics

就像临时队列一样,可以使用临时主题通过在应用程序生存期内存在的临时实体来启用发布/订阅。Just like Temporary Queues, Temporary Topics exist to enable publish/subscribe through a temporary entity that exists for the lifetime of the application.

若要创建临时主题,请使用 JMSContext 类中的以下方法:To create a temporary topic, utilize the below methods in the JMSContext class -

TemporaryTopic createTemporaryTopic()

Java 消息服务 (JMS) 订阅Java message service (JMS) subscriptions

尽管它们在语义上类似于订阅(即,存在于主题上并启用发布/订阅语义),但 Java 消息服务规范引入了给定订阅的共享非共享持久非持久特性概念。While, these are semantically similar to the Subscriptions (i.e. exist on a topic and enable publish/subscribe semantics), the Java Message Service spec introduces the concepts of Shared, Unshared, Durable and Non-durable attributes for a given subscription.

备注

以下订阅在 Azure 服务总线高级层预览版中可用,用于通过 Azure 服务总线 JMS 库连接到 Azure 服务总线的客户端应用程序。The below subscriptions are available in Azure Service Bus Premium tier for Preview for client applications connecting to Azure Service Bus using the Azure Service Bus JMS library.

对于公共预览版,无法使用 Azure 门户创建这些订阅。For the Public preview, these subscriptions cannot be created using the Azure portal.

共享持久订阅Shared durable subscriptions

当某个主题上发布的所有消息都要由某个应用程序接收并处理时,可使用共享持久订阅,无论该应用程序是否任何时候都主动使用该订阅中的消息。A shared durable subscription is used when all the messages published on a topic are to be received and processed by an application, regardless of whether the application is actively consuming from the subscription at all times.

由于这是一个共享订阅,因此,通过身份验证后可以从服务总线接收消息的任何应用程序都可以从订阅中接收消息。Since this is a shared subscription, any application that is authenticated to receive from Service Bus can receive from the subscription.

若要创建共享持久订阅,请使用 JMSContext 类中的以下方法:To create a shared durable subscription, use the below methods on the JMSContext class -

JMSConsumer createSharedDurableConsumer(Topic topic, String name)

JMSConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector)

除非使用 JMSContext 类上的 unsubscribe 方法删除了共享持久订阅,否则该订阅将一直存在。The shared durable subscription continues to exist unless deleted using the unsubscribe method on the JMSContext class.

void unsubscribe(String name)

非共享持久订阅Unshared durable subscriptions

与共享持久订阅一样,当某个主题上发布的所有消息都要由某个应用程序接收并处理时,可使用非共享持久订阅,无论该应用程序是否任何时候都主动使用该订阅中的消息。Just like a shared durable subscription, an unshared durable subscription is used when all the messages published on a topic are to be received and processed by an application, regardless of whether the application is actively consuming from the subscription at all times.

不过,由于这是一个非共享的订阅,因此只有创建该订阅的应用程序才能从其中接收消息。However, since this is an unshared subscription, only the application that created the subscription can receive from it.

若要创建非共享持久订阅,请使用 JMSContext 类中的以下方法:To create an unshared durable subscription, use the below methods from JMSContext class -

JMSConsumer createDurableConsumer(Topic topic, String name)

JMSConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal)

备注

noLocal 功能当前不受支持,将被忽略。The noLocal feature is currently unsupported and ignored.

除非使用 JMSContext 类上的 unsubscribe 方法删除了非共享持久订阅,否则该订阅将一直存在。The unshared durable subscription continues to exist unless deleted using the unsubscribe method on the JMSContext class.

void unsubscribe(String name)

共享非持久订阅Shared non-durable subscriptions

当多个客户端应用程序需要接收和处理来自单个订阅的消息时,会使用共享非持久订阅,直到它们主动使用/接收其中的消息为止。A shared non-durable subscription is used when multiple client applications need to receive and process messages from a single subscription, only until they are actively consuming/receiving from it.

由于订阅不是持久的,因此不会持久保存。Since the subscription is not durable, it is not persisted. 在没有主动使用者的情况下,此订阅不会接收消息。Messages are not received by this subscription when there are no active consumers on it.

若要创建共享非持久订阅,请创建一个 JmsConsumer,如 JMSContext 类中的以下方法中所示:To create a shared non-durable subscription, create a JmsConsumer as shown in the below methods from the JMSContext class -

JMSConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName)

JMSConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName, String messageSelector)

只要有主动使用者从中接收消息,共享非持久订阅就会一直存在。The shared non-durable subscription continues to exist until there are active consumers receiving from it.

非共享非持久订阅Unshared non-durable subscriptions

当客户端应用程序需要接收和处理来自订阅的消息时,会使用非共享非持久订阅,直到它主动使用其中的消息为止。An unshared non-durable subscription is used when the client application needs to receive and process message from a subscription, only until it is actively consuming from it. 此订阅上只能有一个使用者,即创建了该订阅的客户端。Only one consumer can exist on this subscription, i.e. the client that created the subscription.

由于订阅不是持久的,因此不会持久保存。Since the subscription is not durable, it is not persisted. 在没有主动使用者的情况下,此订阅不会接收消息。Messages are not received by this subscription when there is no active consumer on it.

若要创建非共享非持久订阅,请创建一个 JMSConsumer,如 JMSContext 类中的以下方法中所示:To create an unshared non-durable subscription, create a JMSConsumer as shown in the below methods from the JMSContext class -

JMSConsumer createConsumer(Destination destination)

JMSConsumer createConsumer(Destination destination, String messageSelector)

JMSConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal)

备注

noLocal 功能当前不受支持,将被忽略。The noLocal feature is currently unsupported and ignored.

只要有主动使用者从中接收消息,非共享非持久订阅就会一直存在。The unshared non-durable subscription continues to exist until there is an active consumer receiving from it.

消息选择器Message selectors

正如常规服务总线订阅存在筛选器和操作一样,JMS 订阅存在消息选择器Just like Filters and Actions exist for regular Service Bus subscriptions, Message Selectors exist for JMS Subscriptions.

消息选择器可在每个 JMS 订阅上设置,并作为消息标头属性的筛选条件存在。Message selectors can be set up on each of the JMS subscriptions and exist as a filter condition on the message header properties. 只会传递其标头属性与消息选择器表达式匹配的消息。Only messages with header properties matching the message selector expression are delivered. 如果值为 null 或空字符串,则表示不存在与 JMS 订阅/使用者对应的消息选择器。A value of null or an empty string indicates that there is no message selector for the JMS Subscription/Consumer.

后续步骤Next steps

有关使用服务总线消息传送的详细信息和示例,请参阅以下高级主题:For more information and examples of using Service Bus messaging, see the following advanced topics: