Giter Site home page Giter Site logo

geolocation's Introduction

This application uses PHP 8 e Kafka to translate IPs into geographical locations using the IPStack free API.

Topology

Application lifecycle:
  • A PHP process consumes a Kafka Topic entry
  • Incoming messages are sent to IPStack
  • A new message is created using the returned IP geolocation data
  • The new message is sent to a Kafka Topic output
  • The request per client + IP is cached in Redis for 30 minutes.

How to set up

  1. Get free API Access Key and put the value in .env variable IPSTACK_ACCESS_KEY
  2. Run docker-compose up -d
  3. done.

How to test

  1. Start consume the output kafka topic running ./bin/consume-output-topic.sh
  2. Open a Kafka Producer running ./bin/open-input-producer.sh and send a new message:
    Input message sample:

    {"ip": "2001:1284:f013:2c2c:13d9:135d:aff9:c52d", "clientId": 1}
  3. A message with the ip geolocation will appear in the consumer window.
    Output message example
    {
      "ip": "2001:1284:f013:2c2c:13d9:135d:aff9:c52d",
      "timestamp": 1647020864,
      "clientId": 1,
      "latitude": -25.427776336669922,
      "longitude": -49.27305221557617,
      "country": "Brazil",
      "region": "Parana",
      "city": "Curitiba"
    }

Run unit tests

./bin/unit-tests.sh

To do:
  • Implement logs using syslog pattern.
  • Test coverage report.

geolocation's People

Contributors

patrickadeelino avatar

Watchers

 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.