Skip to content

Commit 1b0eec3

Browse files
author
Pankaj Agrawal
committed
Ranme method to set custom sqs client
1 parent e4d2b1b commit 1b0eec3

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

docs/content/utilities/batch.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ If you need to pass custom SqsClient such as region to the SDK, you can pass you
198198
public class AppSqsEvent implements RequestHandler<SQSEvent, List<String>> {
199199
// highlight-start
200200
static {
201-
PowertoolsSqs.defaultSqsClient(SqsClient.builder()
201+
PowertoolsSqs.overrideSqsClient(SqsClient.builder()
202202
.build());
203203
}
204204
// highlight-end

powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/PowertoolsSqs.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static <R> R enrichedMessageFromS3(final SQSEvent sqsEvent,
9292
*
9393
* @param client {@link SqsClient} to be used by utility
9494
*/
95-
public static void defaultSqsClient(SqsClient client) {
95+
public static void overrideSqsClient(SqsClient client) {
9696
PowertoolsSqs.client = client;
9797
}
9898

@@ -229,7 +229,7 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
229229
final SqsMessageHandler<R> handler) {
230230
final List<R> handlerReturn = new ArrayList<>();
231231

232-
BatchContext batchContext = new BatchContext(defaultSqsClient());
232+
BatchContext batchContext = new BatchContext(client);
233233

234234
for (SQSMessage message : event.getRecords()) {
235235
try {
@@ -245,10 +245,6 @@ public static <R> List<R> batchProcessor(final SQSEvent event,
245245
return handlerReturn;
246246
}
247247

248-
private static SqsClient defaultSqsClient() {
249-
return client;
250-
}
251-
252248
private static <R> SqsMessageHandler<R> instantiatedHandler(final Class<? extends SqsMessageHandler<R>> handler) {
253249

254250
try {

powertools-sqs/src/test/java/software/amazon/lambda/powertools/sqs/PowertoolsSqsBatchProcessorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import static org.mockito.Mockito.verifyNoInteractions;
2727
import static org.mockito.Mockito.when;
2828
import static software.amazon.lambda.powertools.sqs.PowertoolsSqs.batchProcessor;
29-
import static software.amazon.lambda.powertools.sqs.PowertoolsSqs.defaultSqsClient;
29+
import static software.amazon.lambda.powertools.sqs.PowertoolsSqs.overrideSqsClient;
3030

3131
class PowertoolsSqsBatchProcessorTest {
3232

@@ -44,7 +44,7 @@ void setUp() throws IOException {
4444
.queueUrl("test")
4545
.build());
4646

47-
defaultSqsClient(sqsClient);
47+
overrideSqsClient(sqsClient);
4848
}
4949

5050
@Test

powertools-sqs/src/test/java/software/amazon/lambda/powertools/sqs/internal/SqsMessageBatchProcessorAspectTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static org.mockito.Mockito.verify;
2929
import static org.mockito.Mockito.verifyNoInteractions;
3030
import static org.mockito.Mockito.when;
31-
import static software.amazon.lambda.powertools.sqs.PowertoolsSqs.defaultSqsClient;
31+
import static software.amazon.lambda.powertools.sqs.PowertoolsSqs.overrideSqsClient;
3232

3333
public class SqsMessageBatchProcessorAspectTest {
3434
public static final SqsClient sqsClient = mock(SqsClient.class);
@@ -41,7 +41,7 @@ public class SqsMessageBatchProcessorAspectTest {
4141

4242
@BeforeEach
4343
void setUp() throws IOException {
44-
defaultSqsClient(sqsClient);
44+
overrideSqsClient(sqsClient);
4545
reset(sqsClient);
4646
setupContext();
4747
event = MAPPER.readValue(this.getClass().getResource("/sampleSqsBatchEvent.json"), SQSEvent.class);

0 commit comments

Comments
 (0)