Distributed Lab 3: Message Broker in Go

Distributed Lab 3: Message Broker in Go

Using the lab sheet

There are two ways to use the lab sheet, you can either:

Ratings

Each question is rated to help you balance your work:

  • 🔴 - Easy, strictly necessary.
  • 🔴 🔴 - Medium, still necessary.
  • 🔴 🔴 🔴 - Hard, necessary if you're aiming for higher marks.
  • 🔴 🔴 🔴 🔴 - Hard, useful for coursework extensions.
  • 🔴 🔴 🔴 🔴 🔴 - Hard, beyond what you need for any part of the coursework.

Introduction

We are going to use a variant of the publish-subscribe model which uses a message broker for distributing work between many contributors.

The typical publish-subscribe model sends messages to all subscribers signed up to a topic. This works for distributing events that all subscribers should see or act on. For the case where we want just one subscriber to see an event, we want something more like a worker pool that accepts new machines joining the pool remotely and uses 'take' semantics to avoid workers duplicating work.

Part 1: The Multiply Factory 🔴 🔴

Look at the skeleton code you've been given. There are two complete components:

  1. A broker that handles creating channels, publishing stubs.Pair events to those channels, and subscriptions to those channels. When a subscriber sends a stubs.Subscription to a running instance of the broker, it will get callbacks for work whenever it is available.

  2. A miner that generates stubs.Pair events and publishes them to a multiply channel on the broker.

You should be able to launch the broker with go run broker/broker.go and the miner with go run miner/miner.go -- nothing visible should happen except that the broker will print out a notification that the multiply channel has been created.

Your first task is to complete the Factory in factory/factory.go.

This factory should be a worker that:

  • sets up an RPC server that registers a Multiply procedure. This procedure should accept a stubs.Pair and respond with a stubs.JobReport. You may also want to print out the operation, so you can see what the instance is doing while it's running.
  • connects to the broker as an RPC client.
  • sends a stubs.Subscription request to the multiply channel, containing its own ip:port string and the correct string for the broker to use to call its Multiply procedure.

The required mechanism is illustrated in the sequence diagram below.

Part 1

You'll know if this is working correctly because once the factory is subscribed the broker will start sending it work and printing out the results of jobs.

You should be able to:

  1. Stop and restart the factory.

  2. run a second instance of the factory, and have it also process work. Note: you will need to tell the second factory to use a different port for its RPC server.

Part 2: The Multiply-Divide Pipeline

Part 2a: Division 🔴 🔴

Following the same steps, add a Divide procedure. It should also accept a stubs.Pair as the request and respond with a stubs.JobReport.

Test your new procedure using two miners:

Miner 1
go run miner/miner.go

Miner 2
go run miner/miner.go -topic divide

You'll know the code is working when the broker reports results for division operations. You should be able run multiple instances of your Factory (on different ports), and stop and start each of them.

Part 2b: Creating a Pipeline 🔴 🔴 🔴

In this part you will link your Multiply and Divide procedures to create a pipeline. For every two Multiply results produced, the factory should ask the broker to Divide them by each other.

This can be achieved by adding a new goroutine in the factory. When a Multiply procedure is completed, the factory should send each result to this goroutine. Once the goroutine has received two values, it should Publish a new Pair to the broker under the divide topic. It should then continue to wait for further results from the Multiply procedure.

The required mechanism is illustrated in the sequence diagram below.

Part 2

Test your pipeline using a single "multiply" miner. Do not use a "divide" miner this time.

go run miner/miner.go

You'll know the code is working when the broker reports results for division operations (the divisions will be the result of the pipeline). Again, you should be able run multiple instances of your Factory (on different ports), and stop and start each of them.

Part 3: Triplets 🔴 🔴 🔴

The entire pipeline currently operates on stubs.Pairs. Modify it so that it instead works with Triplets of three integers. As well as the factory, you will need to edit the miner and broker code to accomplish this, and make a decision about what Divide means for three integer arguments.

Similar Resources

An n:m message multiplexer written in Go

An n:m message multiplexer written in Go

What is Gollum? Gollum is an n:m multiplexer that gathers messages from different sources and broadcasts them to a set of destinations. Gollum origina

Dec 23, 2022

A library for scheduling when to dispatch a message to a channel

gosd go-schedulable-dispatcher (gosd), is a library for scheduling when to dispatch a message to a channel. Implementation The implementation provides

Sep 27, 2022

:incoming_envelope: A fast Message/Event Hub using publish/subscribe pattern with support for topics like* rabbitMQ exchanges for Go applications

Hub 📨 A fast enough Event Hub for go applications using publish/subscribe with support patterns on topics like rabbitMQ exchanges. Table of Contents

Dec 17, 2022

Go simple async message bus

Go simple async message bus

🚌 message-bus Go simple async message bus. 📖 ABOUT Contributors: Rafał Lorenz Want to contribute ? Feel free to send pull requests! Have problems, b

Dec 29, 2022

A single binary, simple, message queue.

MiniQueue A stupid simple, single binary message queue using HTTP/2. Most messaging workloads don't require enormous amounts of data, endless features

Nov 9, 2022

GTA(Go Task Async) is a lightweight reliable asynchronous task and transaction message library for Golang

GTA (Go Task Async) is a lightweight and reliable asynchronous task and transaction message library for by golang.

Jun 4, 2022

The Xiaomi message push service is a system-level channel on MIUI and is universal across the platform, which can provide developers with stable, reliable, and efficient push services.

Go-Push-API MiPush、JiPush、UMeng MiPush The Xiaomi message push service is a system-level channel on MIUI and is universal across the platform, which c

Oct 20, 2022

GopherSay allow you to display a message said by a cute random Gopher.

GopherSay About Welcome in GopherSay! GopherSay is inspired by Cowsay program. GopherSay allow you to display a message said by a cute random Gopher.

Nov 23, 2022

Golang module/tool for decoding proto buffer without message definition.

Golang module/tool for decoding proto buffer without message definition.

Golang module/tool for decoding proto buffer without message definition.

Nov 11, 2022
KubeMQ is a Kubernetes native message queue broker

KubeMQ Community is the open-source version of KubeMQ, the Kubernetes native message broker. More about KubeMQ

Nov 20, 2021
ChanBroker, a Broker for goroutine, is simliar to kafka

Introduction chanbroker, a Broker for goroutine, is simliar to kafka In chanbroker has three types of goroutine: Producer Consumer(Subscriber) Broker

Aug 12, 2021
Simple, high-performance event streaming broker

Styx Styx is a simple and high-performance event streaming broker. It aims to provide teams of all sizes with a simple to operate, disk-persisted publ

Nov 24, 2022
stratus is a cross-cloud identity broker that allows workloads with an identity issued by one cloud provider to exchange this identity for a workload identity issued by another cloud provider.
stratus is a cross-cloud identity broker that allows workloads with an identity issued by one cloud provider to exchange this identity for a workload identity issued by another cloud provider.

stratus stratus is a cross-cloud identity broker that allows workloads with an identity issued by one cloud provider to exchange this identity for a w

Dec 26, 2021
Tool for collect statistics from AMQP (RabbitMQ) broker. Good for cloud native service calculation.

amqp-statisticator Tool for collect statistics around your AMQP broker. For example RabbitMQ expose a lot information trought the management API, but

Dec 13, 2021
Fetch gas stations prices from Tankerkönig api with Orion Context Broker persistence

tankerkoenig-fuel-machinery - Fetch gas stations from tankerkoenig api and persist them into an Orion Context Broker Scope This project aims to fetch

Feb 14, 2022
go broker interface,you can use kafka,redis,pulsar etc.

broker go broker interface,you can use kafka,redis,pulsar etc. pulsar in docker run pulsar in docker docker run -dit \ --name pulsar-sever \ -p 6650:

Sep 8, 2022
Machinery is an asynchronous task queue/job queue based on distributed message passing.
Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery Machinery is an asynchronous task queue/job queue based on distributed message passing. V2 Experiment First Steps Configuration Lock Broker

Jan 7, 2023
A lightweight, distributed and reliable message queue based on Redis

nmq A lightweight, distributed and reliable message queue based on Redis Get Started Download go get github.com/inuggets/nmq Usage import "github.com

Nov 22, 2021
🔊Minimalist message bus implementation for internal communication

?? Bus Bus is a minimalist event/message bus implementation for internal communication. It is heavily inspired from my event_bus package for Elixir la

Jan 3, 2023