This example is a very basic implementation of microservices architecture built with Spring Boot, Spring Cloud, Eureka Server.
The repository consists of three services:
- The Eureka Server (aka
discovery-service
) that scans for the attached clients (the other microservices) that can easily communicate with one another. - The
queue-service
with JPA, H2 for database persistence, that usesCipher
for decrypting the transaction data we receive fromapi-gateway
and - The
api-gateway
which is responsible for the main interaction, i.e. it will be used to encrypt and send transactions data / retrieve the decrypted data from thequeue-service
.
The project basically consists of three different micro services which are individual spring boot projects which depend on each other (linked using eureka
).
-
Create a security key using
AES
algorithm and save it to a file calledsecurity.key
, the same file needs to exist inqueue-service
andapi-gateway
. The contents of the file have to be string.import java.io.FileWriter; import java.util.Base64; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; public class SomeClass { public static void main (String[] args) { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); // block size is 128bits SecretKey secretKey = keyGenerator.generateKey(); byte[] encoded = secretKey.getEncoded(); String output = Base64.getEncoder().withoutPadding().encodeToString(encoded); FileWriter fw = new FileWriter("security.key"); fw.append(output); fw.flush(); fw.close(); } }
-
Go to each folder and run
mvn spring-boot:run