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
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/amazon-dynamodb-guide.adoc
+73-26Lines changed: 73 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Keep in mind it's actively developed and does not support yet all the features a
19
19
20
20
The Quarkus extension supports two programming models:
21
21
22
-
* Blocking access using the Apache HTTP Client
22
+
* Blocking access using URL Connection HTTP client (by default) or the Apache HTTP Client
23
23
* https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/basics-async.html[Asynchronous programming] based on JDK's `CompletableFuture` objects and the Netty HTTP client.
24
24
25
25
In this guide, we see how you can get your REST services to use the DynamoDB locally and on AWS.
@@ -99,15 +99,15 @@ First, we need a new project. Create a new project with the following command:
This command generates a Maven structure importing the RESTEasy/JAX-RS and DynamoDB Client extensions.
110
-
After this, the `amazon-dynamodb` extension has been added to your `pom.xml`.
110
+
After this, the `dynamodb` extension has been added to your `pom.xml`.
111
111
112
112
== Creating JSON REST service
113
113
@@ -117,7 +117,7 @@ First, let's create the `Fruit` bean as follows:
117
117
118
118
[source,java]
119
119
----
120
-
package org.acme.dynamodb;
120
+
package org.acme.amazon.dynamodb;
121
121
122
122
import java.util.Map;
123
123
import java.util.Objects;
@@ -180,11 +180,11 @@ public class Fruit {
180
180
Nothing fancy. One important thing to note is that having a default constructor is required by the JSON serialization layer. The static `from` method creates a bean based on the `Map`
181
181
object provided by the DynamoDB client response.
182
182
183
-
Now create a `org.acme.dynamodb.AbstractService` that will consist of helper methods that prepare DynamoDB request objects for reading and adding items to the table.
183
+
Now create a `org.acme.amazon.dynamodb.AbstractService` that will consist of helper methods that prepare DynamoDB request objects for reading and adding items to the table.
184
184
185
185
[source,java]
186
186
----
187
-
package org.acme.dynamodb;
187
+
package org.acme.amazon.dynamodb;
188
188
189
189
import java.util.HashMap;
190
190
import java.util.Map;
@@ -232,11 +232,11 @@ public abstract class AbstractService {
232
232
}
233
233
----
234
234
235
-
Then, create a `org.acme.dynamodb.FruitSyncService` that will be the business layer of our application and stores/loads the fruits from DynamoDB using the synchronous client.
235
+
Then, create a `org.acme.amazon.dynamodb.FruitSyncService` that will be the business layer of our application and stores/loads the fruits from DynamoDB using the synchronous client.
236
236
237
237
[source,java]
238
238
----
239
-
package org.acme.dynamodb;
239
+
package org.acme.amazon.dynamodb;
240
240
241
241
import java.util.List;
242
242
import java.util.stream.Collectors;
@@ -269,7 +269,7 @@ public class FruitSyncService extends AbstractService {
269
269
}
270
270
----
271
271
272
-
Now, edit the `org.acme.dynamodb.FruitResource` class as follows:
272
+
Now, edit the `org.acme.amazon.dynamodb.FruitResource` class as follows:
273
273
274
274
[source,java]
275
275
----
@@ -318,32 +318,64 @@ The implementation is pretty straightforward and you just need to define your en
318
318
== Configuring DynamoDB clients
319
319
320
320
Both DynamoDB clients (sync and async) are configurable via the `application.properties` file that can be provided in the `src/main/resources` directory.
321
+
Additionally, you need to add to the classpath a proper implementation of the sync client. By default the extension uses URL connection HTTP client, so
322
+
add a URL connection client dependency to the `pom.xml` file:
323
+
324
+
[source,xml]
325
+
----
326
+
<dependency>
327
+
<groupId>software.amazon.awssdk</groupId>
328
+
<artifactId>url-connection-client</artifactId>
329
+
</dependency>
330
+
----
331
+
332
+
If you want to use Apache HTTP client instead, configure it as follows:
333
+
[source,properties]
334
+
----
335
+
quarkus.amazon.sync-client.dynamodb.type=apache
336
+
----
337
+
338
+
And add following dependency to the application `pom.xml`:
339
+
[source,xml]
340
+
----
341
+
<dependency>
342
+
<groupId>software.amazon.awssdk</groupId>
343
+
<artifactId>apache-client</artifactId>
344
+
<exclusions>
345
+
<exclusion>
346
+
<groupId>commons-logging</groupId>
347
+
<artifactId>commons-logging</artifactId>
348
+
</exclusion>
349
+
</exclusions>
350
+
</dependency>
351
+
----
352
+
NOTE: It's important to exclude `commons-logging` from the client dependency to force Apache HTTP client to use Quarkus logger.
321
353
322
354
If you're going to use a local DynamoDB instance, configure it as follows:
- `quarkus.dynamodb.aws.region` - It's required by the client, but since you're using a local DynamoDB instance you can pick any valid AWS region.
335
-
- `quarkus.dynamodb.aws.credentials.type` - Set `STATIC` credentials provider with any values for `access-key-id` and `secret-access-key`
336
-
- `quarkus.dynamodb.endpoint-override` - Override the DynamoDB client to use a local instance instead of an AWS service
366
+
- `quarkus.amazon.aws.dynamodb.region` - It's required by the client, but since you're using a local DynamoDB instance you can pick any valid AWS region.
367
+
- `quarkus.amazon.aws.dynamodb.credentials.type` - Set `static` credentials provider with any values for `access-key-id` and `secret-access-key`
368
+
- `quarkus.amazon.dynamodb.endpoint-override` - Override the DynamoDB client to use a local instance instead of an AWS service
337
369
338
370
If you want to work with an AWS account, you'd need to set it with:
Copy file name to clipboardExpand all lines: extensions/amazon-dynamodb/deployment/src/main/java/io/quarkus/dynamodb/deployment/DynamodbClientBuildItem.java
0 commit comments