Giter VIP home page Giter VIP logo

queuepro's Introduction

S-QUEUE Pro

QueuePro basically helps you to call all the API calls to external services through this and retries if fails.

How QueuePro works ?

QueuePro basically acts like a broker between your application and external webservices. when a request a come to the default queue it will call the web services with the data provided in the payload. if the response we get is not a 200 or an empty body, QueuePro will retry the request in 2 minutes. This process will happen for maxium 5 times for period of 10 mins.

When a external call receives a success response, QueuePro will immediately send the response and payload combined to the success queue, so the consumers of that queue will be able to consume them. QueuePro will also will listen for the success queues calls, thus handling error responses as same as the default queue.

QueuePro will give up retrying after 5th time and Negatively acknowledges to the respective queue.

Payload structure

For QueuePro to work, you need a basic JSON payload structure as mentioned below.

{  
   "url":"http://example.com/test",
   "body":{  
      "some_key":"some-value",
      "some_other_key":true,
      "authentication": "username:password"
   },
   "method": "POST",
   "callback_data": {
        "url": "http://example.com/test-url",
        "body":{  
          "action": "done"
        },
        "method": "POST"
   }
}

Authenticated resources

QueuePro supports basic authentication for now.

{
"authentication":"username:password"
}

As mentioned above you must have the authentication field filled with username and password separated by a ":", QueuePro will handle the rest for you.

How to add a new queue to the QueuePro

All the configurations for the QP are stored in application.yml. These are the default configs for the QP beside default Spring configs.

membership-consumer:
  api_queue: "membership_api_requests_queue"
  success_queue: "membership_api_requests_success_queue"
  exchange: "membership_exchange"
  routing_key: "membership_key_default"
  success_routing_key: "membership_key_success"
  x_delay: 2000

Creating a new consumer

Creating a consumer is not as hard as it sounds. below are the steps to create you own queue consumer.

  • Create a new JAVA class under the membershipconsumer.consumers package
  • Extend it from BaseConsumer and implement it from ChannelAwareMessageListener (you can implement any message listener)
  • You can use isSuccess() method to check the successes of the external API call and handleFailed() method to handle the failed fails. These methods are already implemented, but if you want to use your own logic you are free to override them.
class MyNewConsumer extends BaseConsumer implements ChannelAwareMessageListener {
    
        @Autowired
        private RESTCallHelper restCallHelper;
    
        @Autowired
        private RabbitMQMessageHelper rabbitMQMessageHelper;
        
        if (isSuccess()) {
            // your success logic
        } else {
            handleFailed();
        }
    
}

About BaseConsumer

BaseConsumer is the parent class that handles all the queue logic and letting us to separate queue logic. You can use isSuccess() method to check the successes of the external API call and handleFailed() method to handle the failed fails. These methods are already implemented, but if you want to use your own logic you are free to override them.

Testing

queuepro's People

Contributors

sithiraik95 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.