Giter Club home page Giter Club logo

flusswerk-example's Introduction

Flusswerk Application Example

This application simulates a simple indexing application to show the Flusswerk framework in action.

Overview

The data processing logic is split in three components:

The Reader receives a message from RabbitMQ and loads the corresponding document (as instance of Document).

@Component
public class Reader implements Function<IndexMessage, Document> {

  @Override
  public Document apply(IndexMessage indexMessage) {
    Document document;
    try {
      document = loadDocument(indexMessage.getItemId());
    } catch (IOException exception) {
      throw new StopProcessingException(
              "Could not load document for id {}", indexMessage.getItemId())
          .causedBy(exception);
    }
    return document;
  }

  private Document loadDocument(String itemId) throws IOException {
      // ...
  }

}

The Transformer then takes the document and builds the required data for the Indexing API (an IndexDocument):

@Component
public class Transformer implements Function<Document, IndexDocument> {

  @Override
  public IndexDocument apply(Document document) {
    IndexDocument indexDocument = new IndexDocument();
    // ...
    return indexDocument;
  }
}

The Writer finally takes the processed data, writes it to the Indexing API and sends messages to notify the next processing application.

@Component
public class Writer implements Function<IndexDocument, Message> {

  private static final Logger LOGGER = LoggerFactory.getLogger(Writer.class);

  @Override
  public Message apply(IndexDocument indexDocument) {
    String id = (String) indexDocument.get("id");
    try {
      sendToSearchService(indexDocument);
    } catch (Exception exception) {
      throw new RetryProcessingException(
              "Could not index document for id %s, will try again later", id)
          .causedBy(exception);
    }
    return new RefreshWebsiteMessage(id, "search");
  }
}

Try yourself:

To try yourself, get the repository and RabbitMQ-Server:

$ git clone https://github.com/dbmdz/flusswerk-example.git
$ cd flusswerk-example
$ docker-compose up

Then start the flusswerk-example Application from your IDE and open the RabbitMQ-Management UI at http://localhost:15672 (Login in as guest/guest).

Drop the following message into the queue search.index:

{ "itemId": "42", "tracingId": "12345" }

In the queue search.publish, you will find the outgoing message send by the Writer:

{
    "envelope":{},
    "tracingId":"12345",
    "itemId":"42",
    "source":"search"
}

The field envelope contains Flusswerk specific metadata and is usually only used by the Framework itself.

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.