Suljettu

Racket programming -- 4

Simulate the publish-subscribe communication pattern in Go. Your solution should have at least two publishers and three subscribers, all implemented as goroutines. The publishers will send messages on specific topics at random intervals to all subscribers on those topics. The subscribers will subscribe to topics and will display the messages received on the console.

Get the initial code from: [login to view URL]

Example

To illustrate, consider the following messages on two different topics: “bees” and “Colorado.”

“bees” messages:

"bees are pollinators,"

"bees produce honey,"

"all worker bees are female,"

"bees have 5 eyes," and

"bees fly about 20mph."

“Colorado” messages:

"Colfax in Denver is the longest continuous street in America,"

"Colorado has the highest mean altitude of all the states," and

"Colorado state flower is the columbine."

Your simulation should create two publishers, one for each set of topic messages. You should also create at least three subscribers. Let’s say “John” wants to subscribe to “bees” type of messages, while “Mary” wants to subscribe to not only “bees” but also “Colorado” type of messages.

A typical output of this simulation would look like the following:

Mary received: Colfax in Denver is the longest continuous street in America

Mary received: bees produce honey

John received: bees produce honey

Mary received: Colorado has the highest mean altitude of all the states

John received: all worker bees are female

Mary received: all worker bees are female

Mary received: bees have 5 eyes

John received: bees have 5 eyes

Mary received: Colorado state flower is the columbine

Mary received: bees fly about 20mph

John received: bees fly about 20mph

The picture below gives a high-level visual of the scenario to help your comprehension.

Implementation

Although it is up to you how to implement this project, we suggest using the following struct:

type PubSub struct {

mu [login to view URL]

topics map[string][]chan string

}

PubSub has a semaphore named “mu” to control access to the map of communication channels (note that the map’s key is a string with the topic name). The idea is to create a new channel for each new subscriber of a particular topic. The publisher will send the message to ALL the channels associated with a particular topic.

We suggest the following methods associated with the PubSub struct:

Method

Description

(ps PubSub) subscribe (topic string) chan string

creates and returns a new channel on a given topic, updating the PubSub struct

(ps PubSub) publish (topic string, msg string)

writes the given message on all the channels associated with the given topic

For the goroutines we suggest the following functions:

Function

Description

publisher(ps PubSub, topic string, msgs[]string)

sends messages taken from a given array of message, one at a time and at random intervals, to all topic subscribers

subscriber(ps PubSub, name string, topic string)

reads and displays all messages received from a particular topic

If you are implementing your own solution, make sure you fulfill the following requirements:

each publisher runs as a goroutine;

each subscriber runs as a goroutine;

publishers and subscribers communicate using channels;

there shouldn't be a limit on the number of messages, publishers, and subscribers;

the solution should be thread-safe so any shared object must have its access properly synchronized; and

you should be able to reproduce a similar output as the given example.

Taidot: Prolog, Lisp, C-ohjelmointi, Scala, Racket

Näytä lisää: project mail method, python programming web bot project website, programming example small project, programming billing report project posts, project correlation quantitative methods, programming language small project, programming logic mlm project, sample project business research methods, programming linked list project, programming java atm project, programming console application project, object oriented programming media player project, programming java thesis project, programming math kids project, programming personal assistant project, programming small memory project, magento show 1 2 3 4 5 project type fixed hourly, programming for my project, Racket programming, linear programming problem using the graphical method filetype excel

Tietoa työnantajasta:
( 423 arvostelua ) Mutrah, Oman

Projektin tunnus: #28418029

2 freelanceria on tarjonnut keskimäärin $75 tähän työhön

msavinash1139

Hi, I've looked at your requirements and I'd like to tell you I'm almost half way completed. I'm well experienced with Go and I've also worked on similar personal projects. If you'd like to use my services, please let Lisää

$70 USD 7 päivässä
(1 arvostelu)
2.5
(0 arvostelua)
0.0