This repository has been archived by the owner on Jun 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an actor that publishes create messages to Kafka
- Loading branch information
Showing
8 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Sends messages to Kafka when a work is created | ||
class NotifyKafkaActor < Hyrax::Actors::AbstractActor | ||
# @param [Hyrax::Actors::Environment] env | ||
# @return [Boolean] true if create was successful | ||
def create(env) | ||
next_actor.create(env) && publish_to_kafka('created', env) | ||
end | ||
|
||
private | ||
|
||
# @param action [String] what action was taken | ||
# @param env [Environment] the environment of the action | ||
def publish_to_kafka(action, env) | ||
kafka.deliver_message(message(action, env), | ||
topic: Settings.kafka.topic) | ||
true | ||
end | ||
|
||
def kafka | ||
Kafka.new(seed_brokers: Settings.kafka.seed_brokers, | ||
client_id: Settings.kafka.client_id) | ||
end | ||
|
||
# @return [String] a JSON encoded message to send to Kafka | ||
def message(action, env) | ||
{ action: action, work: work_message(env) }.to_json | ||
end | ||
|
||
def work_message(env) | ||
{ id: env.curation_concern.id, title: env.curation_concern.title } | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe NotifyKafkaActor do | ||
describe "the middleware" do | ||
subject { Hyrax::CurationConcern.actor_factory.middlewares } | ||
|
||
it { is_expected.to include described_class } | ||
end | ||
end |
This file contains 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