ActiveDev Inc.
  • Home
  • ADCLOUD
    • Getting Started
    • Developing a Microservice
    • Reference
  • Services
  • About
  • Contact
  • Articles

ADCLOUD

Making Microservices Simple
AD Cloud is a collection of projects that will provide common configurations and functions simplifying implementation.

developing a microservice

In order to have a microservice be part of the AD Cloud environment, the following steps should be taken:
  1. Ensure AD Cloud is up and running. Please refer to AD Cloud - Getting Started
  2. Create a boostrap.properties file that will define discovery and config info:
  3. Create an application.properties file and copy it to the config-repo with a file name format of: <appname>-<spring.profile>.properties
  4. Add each endpoint as a permission in the ACL database. Refer to the schema-mysql.sql  script for an example.
  5. Include the adservice starter dependency in the pom.xml
            <dependency>
                <groupId>com.activedevsolutions.cloud</groupId>
                <artifactId>adservice-spring-boot-starter</artifactId>
                <version>version#</version>
            </dependency>

NOTE: If you wish to test your microservice through the gateway with security turned on, it will also be necessary to map the permissions to a role --> group --> user.

Template Service
The template service project serves as an example for a custom microservice. It can be found here: services/templateservice

It already contains the bootstrap.properties file, an application.properties file in the config repo, and the starter project so steps 1, 2, 3, and 5 above are already covered. Lets go ahead and start it up:
  1. cd <local_git_dir>/services/template
  2. mvn spring-boot:run
  3. Check the Eureka Dashbaord. It should now be registered.
  4. Check the Hystrix Dashboard. Its not showing up there. This is because we have to run at least one request through before it will.
  5. Lets run a request through the gateway: http://localhost:8080/gateway/template-service/template/v1.0/items?access_token=<token>
  6. Now we receive an error that we don't have permission. This is because we haven't executed step 4 from "Creating a Microservice" yet. But. It's great to see that we have security enforced with minimal effort.
  7. ​Lets add some permissions to our existing roles:
  8. INSERT INTO sec_permission (name, endpoint) VALUES ('Template Get Items', '^/template-service/template/v1.0/items.GET$');
    INSERT INTO sec_role_permission (role_id, permission_id) VALUES ((SELECT id FROM sec_role WHERE name = 'READ-ONLY'), (SELECT id FROM sec_permission WHERE name = 'Template Get Items'));
    INSERT INTO sec_role_permission (role_id, permission_id) VALUES ((SELECT id FROM sec_role WHERE name = 'READ-WRITE'), (SELECT id FROM sec_permission WHERE name = 'Template Get Items'));
  9. Lets run a request through the gateway again: http://localhost:8080/gateway/template-service/template/v1.0/items?access_token=<token>
  10. Check the Hystrix Dashboard. It should look something like this:
Picture
Conclusion
This demonstrates what Spring Cloud, Netflix OSS, and ADCloud have to offer. With just a few steps, custom microservices can have RBAC, Discovery, Central configuration, and Circuit breaking functionality.

Of course, it doesn't just stop here. Custom Zuul filters and additional functionality in the adservice layer open up possibilities
Site powered by Weebly. Managed by SiteGround
  • Home
  • ADCLOUD
    • Getting Started
    • Developing a Microservice
    • Reference
  • Services
  • About
  • Contact
  • Articles