Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcaster 448 #22

Merged
merged 8 commits into from
Dec 20, 2016
29 changes: 29 additions & 0 deletions islandora-connector-broadcast/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'osgi'

description = 'Islandora CLAW Broadcaster'

dependencies {
compile group: 'org.apache.camel', name: 'camel-core', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to leave this here, but I'd note that you're not actually using SLF4J in the code. (You may want to at some future point, but I'd probably remove this until that time comes).

testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
}

jar {
manifest {
description project.description
docURL project.docURL
vendor project.vendor
license project.license

instruction 'Import-Package', "org.apache.camel;version=\"${camelVersionRange}\",${defaultOsgiImports}"
instruction 'Export-Package', 'ca.islandora.alpaca.connector.broadcast'
}
}

artifacts {
archives (file('build/cfg/main/ca.islandora.alpaca.connector.broadcast.cfg')) {
classifier 'configuration'
type 'cfg'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Incoming queue/topic on the broker of your choice.
# Replace the 'broker' prefix with the broker for your system.
# E.g. activemq, zeromq, etc...
input.stream=broker:queue:islandora-connector-broadcast

# Header that contains the recipient list
recipients.header=ca.islandora.alpaca.connector.broadcast.recipients
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just my own personal preference, but I like to use a convention more like this for naming headers: CamelClawBroadcasterRecipients. This makes it a little easier to refer to the header in simple expressions, since you can refer to it like this: simple("${header.CamelClawBroadcasterRecipients}"). There certainly are camel components that use the ca.islandora.alpaca.... convention, and Fedora's JMS module uses org.fcrepo.jms.___, but for most things that run entirely inside Camel, I've seen the pattern I recommended above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that. It's certainly shorter and easier on the eyes. I was checking out Fedora's messages and rolled with it when looking for a convention, since I figured the X-Islandora-BlahBlah style was more for HTTP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you may decide on something like CamelAlpacaBroadcasterRecipients or the like -- whatever you think best fits.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to Islandora Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* The Islandora Foundation licenses this file to you under the MIT License.
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ca.islandora.alpaca.connector.broadcast;

import org.apache.camel.builder.RouteBuilder;

/**
* A content router distributing messages to multiple endpoints.
*
* @author Daniel Lamb
*/
public class EventRouter extends RouteBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that I've noticed when I generated the Javadocs for our Camel code is that I've got about a dozen EventRouter classes. You may want to think about naming this something like BroadcastEventRouter or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.


/**
* Configure the message route workflow.
*/
public void configure() throws Exception {

// Distribute message based on configured header.
from("{{input.stream}}")
.routeId("MessageBroadcaster")
.description("Broadcast messages from one queue/topic to other specified queues/topics.")
.log("Distributing message: ${headers[JMSMessageID]} with timestamp ${headers[JMSTimestamp]}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where SLF4J could really be used. By using the .log(level, logger, message) interface instead of the simple one here, your users will be able to have more control over the logging of these messages. Here's an example: https://github.com/fcrepo4-exts/fcrepo-camel-toolbox/blob/master/fcrepo-serialization/src/main/java/org/fcrepo/camel/serialization/SerializationRouter.java#L116

With this, you can set the logging level in Karaf (for example) to include or exclude the messages from this particular route; otherwise, you don't have quite such fine-grained control.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll definitely update to use that instead. I certainly want users to control the logging level through Karaf if possible.

.recipientList(simple("${headers[{{recipients.header}}]}"))
.ignoreInvalidEndpoints();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<cm:property-placeholder persistent-id="ca.islandora.alpaca.connector.broadcast" update-strategy="reload">
<cm:default-properties>
<cm:property name="input.stream" value="broker:queue:islandora-connector-broadcast" />
<cm:property name="recipients.header" value="ca.islandora.alpaca.connector.broadcast.recipients" />
</cm:default-properties>
</cm:property-placeholder>

<reference id="broker" interface="org.apache.camel.Component" filter="(osgi.jndi.service.name=acrepo/Broker)"/>

<camelContext id="IslandoraConnectorBroadcast" xmlns="http://camel.apache.org/schema/blueprint">
<package>ca.islandora.alpaca.connector.broadcast</package>
</camelContext>
</blueprint>
15 changes: 13 additions & 2 deletions karaf/src/main/resources/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@
<feature version="${camelVersion}">camel</feature>
<feature version="${activemqVersion}">activemq-camel</feature>

<bundle>mvn:ca.islandora.indexing/islandora-indexing-triplestore/${project.version}</bundle>
<bundle>mvn:ca.islandora.alpaca/islandora-indexing-triplestore/${project.version}</bundle>

<configfile finalname="/etc/ca.islandora.indexing.triplestore.cfg">mvn:ca.islandora.indexing/islandora-indexing-triplestore/${project.version}/cfg/configuration</configfile>
<configfile finalname="/etc/ca.islandora.indexing.triplestore.cfg">mvn:ca.islandora.alpaca/islandora-indexing-triplestore/${project.version}/cfg/configuration</configfile>

</feature>

<feature name="islandora-connector-broadcast" version="${project.version}" start-level="80">
<details>Distributes a message to a list of queues/topics.</details>

<feature version="${camelVersion}">camel</feature>

<bundle>mvn:ca.islandora.alpaca/islandora-connector-broadcast/${project.version}</bundle>

<configfile finalname="/etc/ca.islandora.alpaca.connector.broadcast.cfg">mvn:ca.islandora.alpaca/islandora-connector-broadcast/${project.version}/cfg/configuration</configfile>

</feature>
</features>
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include ':islandora-karaf'
include ':islandora-indexing-triplestore'
include ':islandora-connector-broadcast'

project(':islandora-karaf').projectDir = "$rootDir/karaf" as File
project(':islandora-indexing-triplestore').projectDir = "$rootDir/islandora-indexing-triplestore" as File
project(':islandora-connector-broadcast').projectDir = "$rootDir/islandora-connector-broadcast" as File