I have seen many examples for creating a domain topic and event subscription using rest API's but I want to create it using the azure java sdk which is already there. any leads would greatly help. thanks
Prerequisites to create Domain Topic and Event Subscription using java SDK
JDK with version 8 or above
Azure subscription
Event Grid Topic or Domain
Following steps for creating a Topic & Domain (Azure CLI)
#create Topic
az eventgrid topic create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
#create Domain
az eventgrid domain create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
Include the Required Packages
Add BOM file:
Include the azure-sdk-bom to your project to take a dependency on GA version of the Library.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>{bom_version_to_target}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
And add the direct dependency in the dependencies section without the version flag
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventgrid</artifactId>
</dependency>
</dependencies>
Authenticate the Client
The authentication can be either a key credential, a shared access signature, or Azure Active Directory token authentication. Refer here
Create the client
Using endpoint and Access key to create the client
// For custom event
EventGridPublisherAsyncClient<BinaryData> customEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts custom event schema>")
.credential(new AzureKeyCredential("<key for the endpoint>"))
.buildCustomEventPublisherAsyncClient();
Using endpoint and SAS token to create the client
EventGridPublisherAsyncClient<CloudEvent> cloudEventAsyncClient = new EventGridPublisherClientBuilder()
.endpoint("<endpoint of your event grid topic/domain that accepts CloudEvent schema>")
.credential(new AzureSasCredential("<sas token that can access the endpoint>"))
.buildCloudEventPublisherAsyncClient();
Refer here for more information
Related
I've been working on containerising an application with the intention of using ECS to manage the creation and deployment of the application to EC2.
Guides I've followed include:
The Spring guide for containerising applications
Deploying Spring Boot on ECS
A guide on adding Parameter Store
Another guide on adding Parameter Store
This hasn't panned out entirely, and I believe I've narrowed it down to the Parameter Store config as the source of the issue.
Right now, pom.xml is pretty light-touch, though I've seen more config needed depending on the scenario:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-parameter-store-config</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
Running locally, outside of a container, I can access parameters with very minimal bootstrap config:
spring.application.name=PxTest
#I would usually provide this...
#cloud.aws.credentials.profile-name=default
#...but it seems like Spring assumes this.
As soon as I containerise it, it fails. I then added:
cloud.aws.stack.auto=false
cloud.aws.region.static=us-east-1
cloud.aws.region.auto=false
As I understand it, this should help Spring find the appropriate parameters - but I've seen very little in the way of documentation or articles describing passing SSM Parameter Store properties into a Spring Boot application running on an ECS-provisioned EC2.
The error messages I can access on the EC2 talk about Docker entering promiscuous state, followed by blocking state, and repeating. Given it works fine without SSM, I suspect this is the Spring application starting up, failing, and then being retriggered repeatedly.
Running locally, the errors I get are:
com.amazonaws.SdkClientException: Failed to connect to service endpoint:
(short version, at EC2ResourceFetcher readResource)
Caused by: java.net.ConnectException: Connection refused
Factory method 'ssmClient' threw Exception; nested exception is com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.
And then a knock-on exception about not being able to instantiate beans because it can't get to the SSM service.
As above, I am providing a region in bootstrap.properties but it seems to be ignoring this locally - but as it will be part of an application stack when deployed, it seems unlikely to me that it'll be the same error locally that is seen on AWS?
Has anyone accomplished this before, or have any resources which may be useful on what information I need to pass into the container to allow it to talk to SSM?
I suggest using the built-in support ECS has for injecting secrets from SSM Parameter Store (or Secrets Manager) as environment variables. That way your code is more environment agnostic, and you can run it locally by just setting environment variables instead of connecting it to an external dependency like SSM Parameter Store.
I try to implement a microservice client to receive multipart form-data. I'm using Eclipse Microprofile and Openliberty. Therefore, I used the example sketched on https://openliberty.io/docs/21.0.0.6/send-receive-multipart-jaxrs.html.
In the example I see a method having a parameter with type IAttachment. However, I don't have a library providing this interface in my workspace (Eclipse).
How do I need to configure my pom.xml to get this interface?
Which library should provide this interface?
The IAttachment class is a WebSphere/Liberty-specific interface, so you'd need to add this dependency to your pom.xml:
<dependency>
<groupId>com.ibm.websphere.appserver.api</groupId>
<artifactId>com.ibm.websphere.appserver.api.jaxrs20</artifactId>
<version>1.1.54</version>
<scope>provided</scope>
</dependency>
In future versions of the Jakarta REST specification, you will be able to use a spec-defined interface, making your app more portable. See https://github.com/eclipse-ee4j/jaxrs-api/issues/418 for more details.
I have a rest application which which talks to google cloud sql and based on some data and I will sent data to pubsub topic. I have developing this two phase. Phase 1 getting data from cloudsql. I have successfully completed this and unit & integration test cases are working fine.
In second step i have included google pubsub dependency.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
</dependency>
when added this I am getting following error
Caused by: java.lang.IllegalArgumentException: A database name must be provided.
As i understand after debugging once include the above dependency the code / testing code doesnt refer application.yml file
Note: In application YML file i use spring datasource uRL to connect to Cloud SQL database (which has db name, cloud sql socket factory, cloud instance and username / password) I dont use GCP specific properties for database. For refering google project id use google:cloud:gcp: project-id:
I have solved the problem by removing spring-cloud-gcp-starter-pubsub dependency and added the google pubsub dependency.
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
</dependency>
However still could not find out the root cause of error
I am using the dependency as shown below in a Quarkus application. Default the endpoint is /graphql. But since I am running this application in a k8s environment behind a ingress, this is not ideal. Anyone has an idea how to change this default endpoint to something like: /<service-name>/graphql?
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-servlet</artifactId>
<version>1.0.1</version>
</dependency>
If you're using the SmallRye GraphQL extension, you can control the endpoint path using application.properties:
quarkus.smallrye-graphql.root-path=/my-path-to-graphql
You can also use variables (with ${variableName} syntax) in the value, so you can inject your service name there.
But to be using that extension you need to adjust the dependency to
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-graphql</artifactId>
</dependency>
Note that it's only available since Quarkus 1.5.0.
I am building a spring boot microservices pointing to AWS dynamodb for database operation. I am using below library to interact: As such operations are working fine with CrudRepository, but it is very slow for mass operation. Do we any option like jdbcTemplate.batchUpdate() for dynamodb?
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>4.5.0</version>
</dependency>
The batchSave available on spring-data-dynamodb uses AWS SDK DynamoDBMapper batchSave which doesn't update the existing item.
DynamoDBMapper.batchSave internally calls AmazonDynamoDB.batchWriteItem() which doesn't support updating the existing item.
DynamoDBMapper batchSave:-
Saves the objects given using one or more calls to the
AmazonDynamoDB.batchWriteItem(BatchWriteItemRequest) API. No version
checks are performed, as required by the API.
This method ignores any SaveBehavior set on the mapper, and always
behaves as if SaveBehavior.CLOBBER was specified, as the
AmazonDynamoDB.batchWriteItem() request does not support updating
existing items.