22
33Azure Event Hubs Checkpoint Store can be used for storing checkpoints while processing events from Azure Event Hubs.
44This package makes use of Redis as a persistent store for maintaining checkpoints and partition ownership information.
5- The ` JedisRedisCheckpointStore ` provided in this package can be plugged in to ` EventProcessor ` .
5+ The ` JedisRedisCheckpointStore ` provided in this package can be plugged in to ` EventProcessorClient ` .
66
77[ Source code] [ source_code ] | [ API reference documentation] [ api_documentation ] | [ Product
88documentation] [ event_hubs_product_docs ] | [ Samples] [ sample_examples ]
@@ -18,7 +18,7 @@ documentation][event_hubs_product_docs] | [Samples][sample_examples]
1818- Azure Event Hubs instance
1919 - Step-by-step guide for [ creating an Event Hub using the Azure Portal] [ event_hubs_create ]
2020- Azure Redis Cache or a suitable alternative Redis server
21- - Step-by-step guide for [ creating a Redis Cache using the Azure Portal] [ redis_cache ]
21+ - Step-by-step guide for [ creating a Redis Cache using the Azure Portal] [ redis_quickstart ]
2222
2323### Include the package
2424#### Include the BOM file
@@ -66,8 +66,9 @@ add the direct dependency to your project as follows.
6666
6767### Authenticate the storage container client
6868
69- In order to create an instance of ` JedisCheckpointStore ` , a ` JedisPool ` object must be created. To make this ` JedisPool ` object, a hostname String and a primary key String are required. These can be used as shown below to create a ` JedisPool ` object.
70-
69+ In order to create an instance of ` JedisCheckpointStore ` , a ` JedisPool ` object must be created. To make this ` JedisPool `
70+ object, a hostname String and a primary key String are required. These can be used as shown below to create a
71+ ` JedisPool ` object.
7172
7273## Key concepts
7374
@@ -77,16 +78,26 @@ Key concepts are explained in detail [here][key_concepts].
7778- [ Create and run an instance of JedisRedisCheckpointStore] [ sample_jedis_client ]
7879- [ Consume events from all Event Hub partitions] [ sample_event_processor ]
7980
80- ### Create an instance of JedisPool with Azure Redis Cache
81+ ### Create an instance of JedisPool
82+
83+ To create an instance of JedisPool using Azure Redis Cache, follow the instructions in
84+ [ Use Azure Cache for Redis in Java] [ redis_quickstart_java ] to fetch the hostname and access key. Otherwise, use
85+ connection information from a running Redis instance.
8186
82- ``` java
83- String hostname = " yourHostName.redis.cache.windows.net" ;
87+ ``` java readme-sample-createJedis
88+ JedisClientConfig clientConfig = DefaultJedisClientConfig . builder()
89+ .password(" <YOUR_REDIS_PRIMARY_ACCESS_KEY>" )
90+ .ssl(true )
91+ .build();
8492
85- String password = " <PRIMARY KEY FOR AZURE REDIS CACHE>" ;
93+ String redisHostName = " <YOUR_REDIS_HOST_NAME>.redis.cache.windows.net" ;
94+ HostAndPort hostAndPort = new HostAndPort (redisHostName, 6380 );
95+ JedisPool jedisPool = new JedisPool (hostAndPort, clientConfig);
8696
87- String name = " <NAME OF THE USER CLIENT> " ; // this can also be a default value as the connection of Redis Cache is not dependent on this value
97+ // Do things with JedisPool.
8898
89- JedisPool jedisPool = new JedisPool (poolConfig, hostname, port, 1000 , 1000 , password, Protocol . DEFAULT_DATABASE , name, true , null , null , null );
99+ // Finally, dispose of resource
100+ jedisPool. close();
90101```
91102
92103### Consume events using an Event Processor Client
@@ -95,38 +106,50 @@ To consume events for all partitions of an Event Hub, you'll create an
95106[ ` EventProcessorClient ` ] [ source_eventprocessorclient ] for a specific consumer group. When an Event Hub is created, it
96107provides a default consumer group that can be used to get started.
97108
98- The [ ` EventProcessorClient ` ] [ source_eventprocessorclient ] will delegate processing of events to a callback function that you
99- provide, allowing you to focus on the logic needed to provide value while the processor holds responsibility for
100- managing the underlying consumer operations.
109+ The [ ` EventProcessorClient ` ] [ source_eventprocessorclient ] will delegate processing of events to a callback function
110+ that you provide, allowing you to focus on the logic needed to provide value while the processor holds responsibility
111+ for managing the underlying consumer operations.
101112
102113In our example, we will focus on building the [ ` EventProcessor ` ] [ source_eventprocessorclient ] , use the
103114[ ` JedisRedisCheckpointStore ` ] [ source_jedisredischeckpointstore ] , and a simple callback function to process the events
104115received from the Event Hubs, writes to console and updates the checkpoint in Blob storage after each event.
105116
106- ``` java
107- JedisPool jedisPool = new JedisPool (poolConfig, hostname, port, 1000 , 1000 , password, Protocol . DEFAULT_DATABASE , name, true , null , null , null );
117+ ``` java readme-sample-createCheckpointStore
118+ JedisClientConfig clientConfig = DefaultJedisClientConfig . builder()
119+ .password(" <YOUR_REDIS_PRIMARY_ACCESS_KEY>" )
120+ .ssl(true )
121+ .build();
122+
123+ String redisHostName = " <YOUR_REDIS_HOST_NAME>.redis.cache.windows.net" ;
124+ HostAndPort hostAndPort = new HostAndPort (redisHostName, 6380 );
125+ JedisPool jedisPool = new JedisPool (hostAndPort, clientConfig);
108126
109127EventProcessorClient eventProcessorClient = new EventProcessorClientBuilder ()
110128 .consumerGroup(" << CONSUMER GROUP NAME >>" )
111- .connectionString(" << EVENT HUB CONNECTION STRING >>" )
129+ .connectionString(" << EVENT HUB NAMESPACE CONNECTION STRING >>" )
130+ .eventHubName(" << EVENT HUB NAME >>" )
112131 .checkpointStore(new JedisRedisCheckpointStore (jedisPool))
113132 .processEvent(eventContext - > {
114133 System . out. println(" Partition id = " + eventContext. getPartitionContext(). getPartitionId() + " and "
115134 + " sequence number of event = " + eventContext. getEventData(). getSequenceNumber());
116135 })
117- .processError(errorContext - > {
118- System . out. println(" Error occurred while processing events " + errorContext . getThrowable(). getMessage());
136+ .processError(context - > {
137+ System . out. println(" Error occurred while processing events " + context . getThrowable(). getMessage());
119138 })
120139 .buildEventProcessorClient();
121140
122141// This will start the processor. It will start processing events from all partitions.
123142eventProcessorClient. start();
124143
125144// (for demo purposes only - adding sleep to wait for receiving events)
126- TimeUnit . SECONDS. sleep(5 );
145+ // Your application will probably keep the eventProcessorClient alive until the program ends.
146+ TimeUnit . SECONDS. sleep(2 );
127147
128148// When the user wishes to stop processing events, they can call `stop()`.
129149eventProcessorClient. stop();
150+
151+ // Dispose of JedisPool resource.
152+ jedisPool. close();
130153```
131154
132155## Troubleshooting
@@ -137,13 +160,6 @@ Azure SDK for Java offers a consistent logging story to help aid in troubleshoot
137160their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help
138161locate the root issue. View the [ logging] [ logging ] wiki for guidance about enabling logging.
139162
140- ### Default SSL library
141-
142- All client libraries, by default, use the Tomcat-native Boring SSL library to enable native-level performance for SSL
143- operations. The Boring SSL library is an uber jar containing native libraries for Linux / macOS / Windows, and provides
144- better performance compared to the default SSL implementation within the JDK. For more information, including how to
145- reduce the dependency size, refer to the [ performance tuning] [ performance_tuning ] section of the wiki.
146-
147163## Next steps
148164
149165Get started by exploring the samples [ here] [ samples_readme ] .
@@ -157,18 +173,17 @@ Guidelines][guidelines] for more information.
157173[ api_documentation ] : https://azure.github.io/azure-sdk-for-java
158174[ event_hubs_create ] : https://docs.microsoft.com/azure/event-hubs/event-hubs-create
159175[ event_hubs_product_docs ] : https://docs.microsoft.com/azure/event-hubs/
160- [ java_8_sdk_javadocs ] : https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html
161176[ jdk_link ] : https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable
162177[ key_concepts ] : https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-blob/README.md#key-concepts
163178[ logging ] : https://github.com/Azure/azure-sdk-for-java/wiki/Logging-with-Azure-SDK
164179[ maven ] : https://maven.apache.org/
165- [ performance_tuning ] : https://github. com/Azure /azure-sdk -for-java/wiki/Performance-Tuning
166- [ redis_cache ] : https://docs .microsoft.com/azure/azure-cache-for-redis/cache-configure
180+ [ redis_quickstart ] : https://learn.microsoft. com/azure /azure-cache -for-redis/quickstart-create-redis
181+ [ redis_quickstart_java ] : https://learn .microsoft.com/azure/azure-cache-for-redis/cache-java-get-started
167182[ samples_readme ] : https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis
168183[ sample_jedis_client ] : https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis/src/samples/java/com/azure/messaging/eventhubs/checkpointstore/jedis/JedisRedisCheckpointStoreSample.java
169- [ sample_event_processor ] : https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis/src/samples/java/com/azure/messaging/eventhubs/checkpointstore/jedis/EventProcessorJedisRedisCheckpointStoreSample .java
170- [ sample_examples ] : https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis
184+ [ sample_event_processor ] : https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis/src/samples/java/com/azure/messaging/eventhubs/checkpointstore/jedis/EventProcessorClientJedisSample .java
185+ [ sample_examples ] : https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis/src/samples
171186[ source_code ] : https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis
172187[ source_eventprocessorclient ] : https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/EventProcessorClient.java
173- [ source_jedisredischeckpointstore ] : https://github.com/Azure/azure-sdk-for-java/tree /main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis
188+ [ source_jedisredischeckpointstore ] : https://github.com/Azure/azure-sdk-for-java/blob /main/sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-jedis/src/main/java/com/azure/messaging/eventhubs/checkpointstore/jedis/JedisRedisCheckpointStore.java
174189[ guidelines ] : https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md
0 commit comments