You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Use Java Message Service 2.0 API with Azure Service Bus Premium
10
10
11
-
This article explains how to use the popular **Java Message Service (JMS) 2.0** API to interact with Azure Service Bus over the Advanced Message Queueing Protocol (AMQP 1.0) protocol.
11
+
This article explains how to use the popular **Java Message Service (JMS) 2.0** API to interact with Azure Service Bus over the Advanced Message Queueing Protocol (AMQP) 1.0 protocol.
12
12
13
13
> [!NOTE]
14
14
> Support for Java Message Service (JMS) 2.0 API is only available in the **premium tier**.>
15
15
16
-
## Pre-requisites
16
+
## Prerequisites
17
17
18
18
### Get started with Service Bus
19
19
@@ -35,16 +35,14 @@ To learn more about how to prepare your developer environment for Java on Azure,
35
35
36
36
## Downloading the Java Message Service (JMS) client library
37
37
38
-
To utilize all the features available in the premium tier, add the following library to the build path of the project.
To utilize all the features available in the premium tier, add the following library to the build path of the project: [azure-servicebus-jms](https://central.sonatype.com/artifact/com.microsoft.azure/azure-servicebus-jms/1.0.0). This package provides some necessary defaults such as prefetch policy values, reconnect policies, Microsoft Entra ID, and Managed Identity support out of the box.
41
39
42
40
> [!NOTE]
43
-
> To add the [Azure-servicebus-jms](https://central.sonatype.com/artifact/com.microsoft.azure/azure-servicebus-jms/1.0.0) to the build path, use the preferred dependency management tool for your project like [Maven](https://maven.apache.org/) or [Gradle](https://gradle.org/).
41
+
> To add the [azure-servicebus-jms](https://central.sonatype.com/artifact/com.microsoft.azure/azure-servicebus-jms/1.0.0) to the build path, use the preferred dependency management tool for your project like [Maven](https://maven.apache.org/) or [Gradle](https://gradle.org/).
44
42
45
43
## Coding Java applications
46
44
47
-
Once the dependencies have been imported, the Java applications can be written in a JMS provider agnostic manner.
45
+
Once the dependencies are imported, the Java applications can be written in a JMS provider agnostic manner.
48
46
49
47
### Connecting to Azure Service Bus using JMS
50
48
@@ -85,7 +83,7 @@ To connect with Azure Service Bus using JMS clients, you need the **connection s
85
83
86
84
### Write the JMS application
87
85
88
-
Once the `Session` or `JMSContext` has been instantiated, your application can use the familiar JMSAPIs to perform both management and data operations. Refer to the list of [supported JMS features](how-to-use-java-message-service-20.md#what-jms-features-are-supported) to see which APIs are supported. Here are some sample code snippets to get started with JMS-
86
+
Once the `Session` or `JMSContext` is instantiated, your application can use the familiar JMSAPIs to perform both management and data operations. Refer to the list of [supported JMS features](how-to-use-java-message-service-20.md#what-jms-features-are-supported) to see which APIs are supported. Here are some sample code snippets to get started with JMS-
89
87
90
88
#### Sending messages to a queue and topic
91
89
@@ -137,13 +135,9 @@ This guide showcased how Java client applications using Java Message Service (JM
137
135
138
136
You can also use ServiceBusAMQP1.0 from other languages, including .NET, C, Python, and PHP. Components built using these different languages can exchange messages reliably and at full fidelity using the AMQP1.0 support in ServiceBus.
139
137
140
-
## Next steps
138
+
## Related content
139
+
140
+
- [UseJMS in Spring to access AzureServiceBus](/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-service-bus)
141
+
- [UseAzureServiceBus with JMS](/azure/developer/java/spring-framework/spring-jms-support)
142
+
141
143
142
-
For more information on AzureServiceBus and details about JavaMessageService (JMS) entities, check out the links below -
143
-
* [ServiceBus-Queues, Topics, and Subscriptions](service-bus-queues-topics-subscriptions.md)
Copy file name to clipboardExpand all lines: articles/service-bus-messaging/service-bus-prefetch.md
+5-20Lines changed: 5 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,9 @@ ms.devlang: csharp
8
8
---
9
9
10
10
# Prefetch Azure Service Bus messages
11
-
When you enable the **Prefetch** feature for any of the official Service Bus clients, the receiver acquires more messages than what the application initially asked for, up to the specified prefetch count. As messages are returned to the application, the client acquires more messages in the background, to fill the prefetch buffer.
11
+
The Prefetch feature fetches messages in the background into a local prefetch buffer up to the prefetch count. Messages are served from the buffer. As it happens, space is freed up in the buffer, and the receiver will prefetch more in the background.
12
12
13
-
## Enable Prefetch
14
-
To enable the Prefetch feature, set the prefetch count of the queue or subscription client to a number greater than zero. Setting the value to zero turns off prefetch.
13
+
To enable the Prefetch feature, set the prefetch count of the queue or subscription client to a number greater than zero. Setting the value to zero turns off prefetch. If there are messages in the prefetch buffer after the feature is turned off, the application receives those messages from the buffer first, and then goes to the service.
15
14
16
15
# [.NET](#tab/dotnet)
17
16
Set the prefetch count property on the [ServiceBusReceiverOptions](/dotnet/api/azure.messaging.servicebus.servicebusreceiveroptions.prefetchcount) and [ServiceBusProcessorOptions](/dotnet/api/azure.messaging.servicebus.servicebusprocessoroptions.prefetchcount) objects.
@@ -35,28 +34,14 @@ Prefetch speeds up the message flow by having a message readily available for lo
35
34
36
35
When you use the [receive and delete](message-transfers-locks-settlement.md#receiveanddelete) mode, all messages that are acquired into the prefetch buffer are no longer available in the queue. The messages stay only in the in-memory prefetch buffer until they're received into the application. If the application ends before the messages are received into the application, those messages are irrecoverable (lost).
37
36
38
-
When you use the [peek lock](message-transfers-locks-settlement.md#peeklock) receive mode, messages fetched into the prefetch buffer are acquired into the buffer in a locked state. They have the timeout clock for the lock ticking. If the prefetch buffer is large, and processing takes so long that message locks expire while staying in the prefetch buffer or even while the application is processing the message, there might be some confusing events for the application to handle. The application might acquire a message with an expired or imminently expiring lock. If so, the application might process the message, but then find that it can't complete the message because of a lock expiration. The application can check the `LockedUntilUtc` property (which is subject to clock skew between the broker and local machine clock).
37
+
When you use the [peek lock](message-transfers-locks-settlement.md#peeklock) receive mode, messages fetched into the prefetch buffer are acquired into the buffer in a locked state. The lock timer starts from the moment the message is prefetched into the buffer. If the prefetch buffer is large, and processing takes so long that message locks expire while staying in the prefetch buffer or even while the application is processing the message, there might be some confusing events for the application to handle. The application might acquire a message with an expired or imminently expiring lock. If so, the application might process the message, but then find that it can't complete the message because of a lock expiration. The application can check the `LockedUntilUtc` property, but keep in mind that there's clock skew between the broker and local machine clock.
39
38
40
-
If the message lock has expired, the application must ignore the message, and shouldn't make any API call on the message. If the message isn't expired but expiration is imminent, the lock can be renewed and extended by another default lock period. If the lock silently expires in the prefetch buffer, the message is treated as abandoned and is again made available for retrieval from the queue. It might cause the message to be fetched into the prefetch buffer and placed at the end. If the prefetch buffer can't usually be worked through during the message expiration, messages are repeatedly prefetched but never effectively delivered in a usable (validly locked) state, and are eventually moved to the dead-letter queue once the maximum delivery count is exceeded.
39
+
If the lock silently expires in the prefetch buffer, the message is treated as abandoned and is again made available for retrieval from the queue. Then the message will be fetched again into the prefetch buffer and placed at the end If the prefetch buffer can't usually be worked through during the message expiration, messages are repeatedly prefetched but never effectively delivered in a usable (validly locked) state, and are eventually moved to the dead-letter queue once the maximum delivery count is exceeded.
41
40
42
-
If an application explicitly abandons a message, the message may again be available for retrieval from the queue. When the prefetch is enabled, the message is fetched into the prefetch buffer again and placed at the end. As the messages from the prefetch buffer are drained in the first-in first-out (FIFO) order, the application may receive messages out of order. For example, the application may receive a message with ID 2 and then a message with ID 1 (that was abandoned earlier) from the buffer.
41
+
If an application explicitly abandons a message, the message might again be available for retrieval from the queue. When the prefetch is enabled, the message is fetched into the prefetch buffer again and placed at the end. As the messages from the prefetch buffer are drained in the first-in first-out (FIFO) order, the application might receive messages out of order. For example, the application might receive a message with ID 2 and then a message with ID 1 (that was abandoned earlier) from the buffer.
43
42
44
43
If you need a high degree of reliability for message processing, and processing takes significant work and time, we recommend that you use the Prefetch feature conservatively, or not at all. If you need high throughput and message processing is commonly cheap, prefetch yields significant throughput benefits.
45
44
46
45
The maximum prefetch count and the lock duration configured on the queue or subscription need to be balanced such that the lock timeout at least exceeds the cumulative expected message processing time for the maximum size of the prefetch buffer, plus one message. At the same time, the lock timeout shouldn't be so long that messages can exceed their maximum time to live when they're accidentally dropped, and so requiring their lock to expire before being redelivered.
47
46
48
-
## Next steps
49
-
50
-
Try the samples in the language of your choice to explore Azure Service Bus features.
51
-
52
-
-[Azure Service Bus client library samples for .NET (latest)](/samples/azure/azure-sdk-for-net/azuremessagingservicebus-samples/)
53
-
-[Azure Service Bus client library samples for Java (latest)](/samples/azure/azure-sdk-for-java/servicebus-samples/)
54
-
-[Azure Service Bus client library samples for Python](/samples/azure/azure-sdk-for-python/servicebus-samples/)
55
-
-[Azure Service Bus client library samples for JavaScript](/samples/azure/azure-sdk-for-js/service-bus-javascript/)
56
-
-[Azure Service Bus client library samples for TypeScript](/samples/azure/azure-sdk-for-js/service-bus-typescript/)
57
-
58
-
Samples for the older .NET and Java client libraries:
59
-
-[Azure Service Bus client library samples for .NET (legacy)](https://github.com/Azure/azure-service-bus/tree/master/samples/DotNet/Microsoft.Azure.ServiceBus/) - See the **Prefetch** sample.
60
-
-[Azure Service Bus client library samples for Java (legacy)](https://github.com/Azure/azure-service-bus/tree/master/samples/Java/azure-servicebus) - See the **Prefetch** sample.
0 commit comments