AWS SQS integration with Spring cloud - spring

I am looking for a simple working demo of integrating Spring cloud to access AWS SQS. I found few samples online but having hard time running this at locally (not on EC2) as its hard to inject required dependencies manually on local run.

Sorry this is a little old, but hopefully it will help someone out there.
I used this example to get my Spring Boot application to receive messages from Amazon SQS. It worked almost perfectly using Spring Boot 1.3 and Spring Framework 4.2, so I won't bother copying what is already written there.
The only thing I did differently was that I put my AWS credentials into my project's .yml file, like so:
# In src/main/resources/application.yml
cloud:
aws:
credentials:
accessKey: ABCDEFGHIJKLMNOPQRSTUVQXYZ
secretKey: aBigSecretKey
region:
auto: true
stack:
auto: false
The AmazonSqsAsync client auto-authenticates using these provided properties, so you don't have to worry about any of the steps of the authentication process. All you have to do is drop these properties into the file, and you're good to go :)
Hope this helps.

you could find a sample with current(spring-boot:2.4) version here Ryanair guides-awspring-localstack-sqs

Related

Spring Cloud Config Server on Pivotal Cloud Foundry

I have two microservices. A Spring Cloud Config Server and another module that implements Spring Cloud Config Client. When I use the default configuration for the Spring Cloud Config Server service (localhost:8888) I can start it locally without any issues, after which I can start my other module as well, using a bootstrap.yml, it clearly finds the Config Server, fetches its properties and starts properly. All good. Now I'd like to push both of these services to Pivotal Cloud Foundry.
The Config Server service works just fine, service is up and running in my Space, and using the browser I can verify that it can still fetch the property files from the specific GitHub repository.
The problem is the other module, the client. I've replaced the default localhost:8888 in its bootstrap.yml file (spring.cloud.config.url parameter) to the now active service in the cloud using the Route bound to it and tried to start it locally. Unfortunately now it simply timeouts during startup. At this point I tried to specify longer timeouts but nothing helps.
Interesting thing is that if I directly copy the URL from the logs that timeouts I see it works properly in the browser locally. So why not in IntelliJ when I try to package the client with the changed parameter?
Sorry, I can't include much details here, but I hope maybe there is a straightforward solution that I've missed. Thanks!

spring cloud data flow custom app config to pass enviromental variables

i am working on Spring cloud data flow Custom source application which gets data from an rest endpoint . I use Spring cloud data flow and Skipper server to push this custom jar to PCF (Pivotal Cloud Foundry) .This works fine but now i want to pass some custom environmental properties to the application .Below is the yaml config i used to deploy the jar to the repo . tried passing below it under the env bucket but seems its not getting picked by the application at runtime..Please suggest
DB_HOST:host_url
DB_PORT:3306
DB_SCHEMA:test
DB_USER: user
DB_PASS:pwd
application.yml for pusing the CUSTOM SOURCE to SCDF App Repo
---
applications:
- name: pocclient
memory: 2G
instances: 1
path: ../target/custom-sink-client-0.0.17-SNAPSHOT.jar
buildpacks:
- java_buildpack
env:
JAVA_VERSION: 1.8.0_+
SPRING_PROFILES_ACTIVE: cloud
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
DB_HOST:host_url
DB_PORT:port
DB_SCHEMA:test
DB_USER:
DB_PASS:
Based on the limited details in the description, it is unclear what you're trying to do with SCDF and a custom-sink, and likewise, in which platform are you provisioning all the components. You may want to edit the post with more details.
In Cloud Foundry, if you want SCDF to deploy apps with config-server binding automatically, you would want to review the ref. guide for more information. The service-instance must exist in the same Org/Space, and the service-instance name is expected to be configured in SCDF, so when SCDF deploys apps on your behalf, it will also bind the app with the service-instance automatically.
In Kubernetes, it'd be a similar mechanism; however, you're expected to provide the config-server URI configuration as an environment variable when deploying the desired apps as bare-pods.

Reading ~/.aws/credentials from Spring Boot Spring Cloud

I am new to AWS and Spring Cloud. I have accomplished a simple AWS Java Application where the AWS credentials are stored in ~/.aws/credentials file. It works just fine. I moved to a new project in Spring Boot and Spring Cloud. I would like to continue using the ~/.aws/credential that I have set up for the Java application. However, I have not been able to find a way to load the credentials from the credentials file. I had to move the access key and secret key to the aws-config.xml.
<aws-context:context-credentials>
<aws-context:simple-credentials access-key="${accessKey:}" secret-key="${secretKey:}"/>
<aws-context:context-resource-loader/>
When I accomplished this, the Spring Boot and Spring Cloud application worked fine. However, keeping the information in the xml file is not the safest way because I am using GitHub.
Can someone point me in the direction whereby I can pull the information from the ~/.aws/credentials file into Spring Boot /Spring Cloud using Maven?
Thank you for taking the time reading my post.
Russ
try below settings
cloud:
aws:
credentials:
instanceProfile: false
useDefaultAwsCredentialsChain: false
profileName: <name>
profilePath: ${user.home}/.aws/credentials
Instance Profile sounds like the right option!
It's a IAM-role that lives on instances, without the need to hardcode credentials in code.
Spring Cloud's Maven setup guide :)

Enable eureka.client.healthcheck

I'm following http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html to build distributed system with Spring Cloud.
All works as expected apart from Eureka Client Healthcheck.
I have
eureka:
client:
healthcheck:
enabled: true
And pointing my service to nonexisten config_server, this results in
http://myservice:8080/health
{
status: "DOWN"
}
But Eureka server still showing this instance as UP and keep sending traffic to it.
What am I missing?
spring-boot: 1.2.8.RELEASE
spring-cloud-netflix : 1.0.4.RELEASE
You have to explicitly set eureka.client.healthcheck.enabled=true to link the Spring Boot health indicator to the Eureka registration. Source code reference: here.
Ok, I think I found it.
According to https://jmnarloch.wordpress.com/2015/09/02/spring-cloud-fixing-eureka-application-status/ this feature will only be available on Spring Cloud 1.1.
To make it work with 1.0.4 I need to implement my own HealthCheckHandler.
Thanks #xtreme-biker for bringing up Spring Cloud version issue.

Example for Spring Cloud Consul with Ribbon for client side load balancing

I see that spring-cloud-consul is live in spring.io [https://spring.io/blog/2015/05/27/spring-cloud-consul-1-0-0-m1-available-now] but I hardly see any reference examples.
I am mainly looking for Service Registration and Service Discovery with Consul and Ribbon as client side load balancer. Could someone give a sample application or an example to refer. I also checked in the git repository for spring-cloud-consul, didn't find any examples there[https://github.com/spring-cloud/spring-cloud-consul]
There is an example in the main repo, spring-cloud-consul-sample, that uses the LoadBalancerClient of which there is a ribbon implementation that will use consul to populate the server list.
I wasn't able to find much information about Consul and Ribbon, but I have found more information about Eueka (it's used by Netflix and it also does service registration/distcovery similiar to Consul). This Spring project seems to be a lot more active. Info about it can be found here: http://cloud.spring.io/spring-cloud-netflix/
This blog post demonstrates how to use spring cloud with Eueka and Ribbon: https://spring.io/blog/2015/07/14/microservices-with-spring
There is also a repo for the tutorial: https://github.com/paulc4/microservices-demo
If you still want to use Consul instead of Eueka, here is a sample project, you should be able to use this along with the blog post above to build a working example: https://github.com/spring-cloud/spring-cloud-consul/tree/master/spring-cloud-consul-sample
I wrote a demo project using Spring Cloud Consul and Spring Cloud Netflix.
I'm using Consul as a service registry, and Ribbon/Hystrix/Feign are used to simplify API service clients.
The project is hosted on GitHub: https://github.com/alexandreroman/number2words.

Resources