Last active
December 3, 2021 08:27
-
-
Save ross-spencer/cd631082a95022dae28dbe9e20c88867 to your computer and use it in GitHub Desktop.
Sample Stomp message queue consumer code for Fedora
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
--Headers: { | |
"destination": "/topic/fedora", | |
"expires": "0", | |
"message-id": "ID:wikibase-36143-1638450997244-4:1:1:1:6", | |
"org.fcrepo.jms.baseURL": "http://141.94.169.145:8080/rest", | |
"org.fcrepo.jms.eventID": "urn:uuid:cd36ab67-4a51-4e88-96ab-b07acf71d625", | |
"org.fcrepo.jms.eventType": "https://www.w3.org/ns/activitystreams#Create", | |
"org.fcrepo.jms.identifier": "/galaxy", | |
"org.fcrepo.jms.resourceType": "http://mementoweb.org/ns#TimeGate,http://www.w3.org/ns/ldp#BasicContainer,http://fedora.info/definitions/v4/repository#Resource,http://mementoweb.org/ns#OriginalResource,http://www.w3.org/ns/ldp#Container,http://www.w3.org/ns/ldp#Resource,http://www.w3.org/ns/ldp#RDFSource,http://fedora.info/definitions/v4/repository#Container", | |
"org.fcrepo.jms.timestamp": "1638519905399", | |
"org.fcrepo.jms.user": "null", | |
"org.fcrepo.jms.userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36", | |
"persistent": "true", | |
"priority": "4", | |
"subscription": "abcd", | |
"timestamp": "1638519905410" | |
} | |
--Body: { | |
"id": "urn:uuid:cd36ab67-4a51-4e88-96ab-b07acf71d625", | |
"type": ["Create"], | |
"name": "create resource", | |
"published": "2021-12-03T08:25:05.399035Z", | |
"actor": [{ | |
"type": "Person", | |
"id": "null" | |
}, { | |
"type": "Application", | |
"name": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" | |
}], | |
"object": { | |
"type": ["http://mementoweb.org/ns#TimeGate", "http://www.w3.org/ns/ldp#BasicContainer", "http://fedora.info/definitions/v4/repository#Resource", "http://mementoweb.org/ns#OriginalResource", "http://www.w3.org/ns/ldp#Container", "http://www.w3.org/ns/ldp#Resource", "http://www.w3.org/ns/ldp#RDFSource", "http://fedora.info/definitions/v4/repository#Container", "http://www.w3.org/ns/prov#Entity"], | |
"id": "http://141.94.169.145:8080/rest/galaxy", | |
"isPartOf": "http://141.94.169.145:8080/rest" | |
}, | |
"@context": ["https://www.w3.org/ns/activitystreams#", { | |
"prov": "http://www.w3.org/ns/prov#", | |
"dcterms": "http://purl.org/dc/terms/", | |
"type": "@type", | |
"id": "@id", | |
"isPartOf": { | |
"@id": "dcterms:isPartOf", | |
"@type": "@id" | |
} | |
}] | |
} |
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
"""Fedora listener | |
Listens for ActiveMQ messages using the stomp message queue library. | |
The equivalent using stomp itself would look as follows; | |
stomp -H localhost -P 61613 | |
> subscribe /topic/fedora | |
Modified from Lyrasis: | |
* https://wiki.lyrasis.org/display/FEDORAM6M1P0/Inspect+Event+Messages | |
""" | |
import json | |
import stomp | |
import signal | |
class Listener(stomp.ConnectionListener): | |
def on_message(self, frames): | |
print("\n\nIncoming Message") | |
print("--Headers:") | |
print(json.dumps(frames.headers, indent=2, sort_keys=True)) | |
print("\n--Body:") | |
print(json.dumps(frames.body, indent=2, sort_keys=True)) | |
connection = stomp.Connection(host_and_ports=[("localhost", 61613)]) | |
connection.set_listener("", Listener()) | |
connection.connect() | |
connection.subscribe(id="abcd", destination="/topic/fedora") | |
while True: | |
signal.pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question is, how does one provide a retroactive argument? Further, is fcrepo configured to store messages so that they can be retroactively sent out? e.g. one possibility?
headers={"activemq.retroactive": "true"}