Hello,
We are using AWS API Gateway and recently replaced AWS API Gateway with Google Cloud Apigee. We had AWS API Gateway integration with AWS SQS so that any message sent on REST endpoint will get directly stored in AWS SQS. In order to implement the same functionality using Apigee, I am using Java callout. Below is the sample code.
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.SendMessageRequest;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import com.apigee.flow.execution.ExecutionContext;
import com.apigee.flow.execution.ExecutionResult;
import com.apigee.flow.execution.spi.Execution;
import com.apigee.flow.message.MessageContext;
public class SendToSQS implements Execution {
@Override
public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) {
try {
// Retrieve AWS credentials and SQS Queue URL from KVM
String awsAccessKey = messageContext.getVariable("aws_access_key");
String awsSecretKey = messageContext.getVariable("aws_secret_key");
String awsRegion = messageContext.getVariable("aws_region");
String queueUrl = messageContext.getVariable("queue_url");
if (awsAccessKey == null || awsSecretKey == null || awsRegion == null || queueUrl == null) {
throw new IllegalArgumentException("AWS credentials or SQS URL are not set in the KVM.");
}
String messageBody = messageContext.getMessage().getContent();
// Initialize SQS Client with retrieved credentials and URL
AwsBasicCredentials awsCreds = AwsBasicCredentials.create(awsAccessKey, awsSecretKey);
SqsClient sqsClient = SqsClient.builder()
.region(Region.of(awsRegion))
.credentialsProvider(StaticCredentialsProvider.create(awsCreds))
.build();
// Send message to SQS
SendMessageRequest sendMsgRequest = SendMessageRequest.builder()
.queueUrl(queueUrl)
.messageBody(messageBody)
.delaySeconds(5)
.build();
sqsClient.sendMessage(sendMsgRequest);
return ExecutionResult.SUCCESS;
} catch (IllegalArgumentException e) {
messageContext.getMessage().setContent("Configuration Error: " + e.getMessage());
return ExecutionResult.ABORT;
} catch (Exception e) {
messageContext.getMessage().setContent("Execution Error: " + e.getMessage());
return ExecutionResult.ABORT;
}
}
}
The build.gradle file is as follows.
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
// AWS SDK v2 for Java
implementation 'software.amazon.awssdk:sqs:2.17.102'
implementation 'com.apigee.edge:expressions:1.0.0'
implementation 'com.apigee.edge:message-flow:1.0.0'
}
The issue is with Apigee dependencies not available in a public domain. How do I get my code compiled? Do I need enterprise Apigee account to download jar locally ?
Thanks,
Mehul