This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MultiplyByTenBolt extends BaseRichBolt | |
| { | |
| OutputCollector collector; | |
| public void execute(Tuple tuple) | |
| { | |
| // Get 'even-digit' from the tuple. | |
| int evenDigit = tuple.getInt(0); | |
| collector.emit(new Values(evenDigit * 10)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class EvenDigitBolt extends BaseRichBolt | |
| { | |
| // To output tuples from this bolt to the next bolt. | |
| OutputCollector collector; | |
| public void execute(Tuple tuple) | |
| { | |
| // Get the 1st column 'random-digit' from the tuple | |
| int randomDigit = tuple.getInt(0); | |
| if (randomDigit % 2 == 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RandomDigitSpout extends BaseRichSpout | |
| { | |
| // To output tuples from spout to the next stage bolt | |
| SpoutOutputCollector collector; | |
| public void nextTuple() | |
| { | |
| int randomDigit = ThreadLocalRandom.current().nextInt(0, 10); | |
| // Emit the digit to the next stage bolt | |
| collector.emit(new Values(randomDigit)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // service-worker.js | |
| // Path is relative to the origin. | |
| const OFFLINE_PAGE_URL = 'offline/offline.html'; | |
| // We’ll add more URIs to this array later. | |
| const ASSETS_TO_BE_CACHED = [OFFLINE_PAGE_URL]; | |
| self.addEventListener('install', event => { | |
| event.waitUntil( | |
| // The Cache API is domain specific and allows an app to create & name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // service-worker.js | |
| // Changing the cache version will cause existing cached resources to be | |
| // deleted the next time the service worker is re-installed and re-activated. | |
| const CACHE_VERSION = 1; | |
| const CURRENT_CACHE = `your-app-name-cache-v-${CACHE_VERSION}`; | |
| const OFFLINE_PAGE_URL = 'offline/offline.html'; | |
| const ASSETS_TO_BE_CACHED = ['offline/offline.css', 'offline/offline.jpg', OFFLINE_PAGE_URL]; | |
| self.addEventListener('install', event => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/environments/development.rb | |
| # … | |
| # Add our own middleware before the ActionDispatch::Static | |
| # middleware and pass it an array of service worker URIs as a | |
| # parameter. | |
| config.middleware.insert_before ActionDispatch::Static, ServiceWorkerManager, ['service-worker.js'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/middleware/service_worker_manager.rb | |
| class ServiceWorkerManager | |
| # We’ll pass 'service_workers' when we register this middleware. | |
| def initialize(app, service_workers) | |
| @app = app | |
| @service_workers = service_workers | |
| end | |
| def call(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // main.go | |
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "github.com/streadway/amqp" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # services/user_event_handler.py | |
| import pika | |
| import json | |
| def emit_user_profile_update(user_id, new_data): | |
| # 'rabbitmq-server' is the network reference we have to the broker, | |
| # thanks to Docker Compose. | |
| connection = pika.BlockingConnection(pika.ConnectionParameters(host='rabbitmq-server')) | |
| channel = connection.channel() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # main.py | |
| from flask import Flask | |
| from flask import request | |
| from flask import jsonify | |
| from services.user_event_handler import emit_user_profile_update | |
| app = Flask(__name__) | |
| @app.route('/users/<int:user_id>', methods=['POST']) |