Skip to content

Instantly share code, notes, and snippets.

@danveloper
danveloper / BuildConfig.groovy
Created March 20, 2013 21:18
ActiveMQ Grails Dependencies -- Real Time Logging Project
dependencies {
...
compile 'org.apache.activemq:activemq-core:5.7.0'
// (this is necessary for namespace support)
compile 'org.apache.xbean:xbean-spring:3.12'
...
}
@danveloper
danveloper / resources.groovy
Created March 20, 2013 21:19
ActiveMQ integration with Spring context -- Real Time Logging Project
beans = {
...
xmlns amq:"http://activemq.apache.org/schema/core"
/* Establish the broker */
amq.broker(useJmx: false, persistent: false) {
amq.transportConnectors() {
amq.transportConnector(uri: "tcp://localhost:61616")
}
}
@danveloper
danveloper / BuildConfig.groovy
Created March 20, 2013 21:19
Spring Integration Grails Dependencies -- Real Time Logging Project
dependencies {
...
compile 'org.springframework.integration:spring-integration-core:2.2.0.RELEASE'
compile 'org.springframework.integration:spring-integration-jms:2.2.0.RELEASE'
compile 'org.springframework.integration:spring-integration-stream:2.2.0.RELEASE'
...
}
@danveloper
danveloper / resources.groovy
Created March 20, 2013 21:20
Spring Integration Resources Configuration -- Real Time Logging
beans = {
...
/* Attach the message adapter */
logServiceActivator(LoggingServiceActivator)
/* Create the log channel, for internal transport */
integration.channel(id: "logChannel")
/* Attach a chain to the log channel, this will delegate the message to the LoggingServiceActivator */
integration.chain("input-channel": "logChannel") {
@danveloper
danveloper / LogMessageCommand.groovy
Created March 20, 2013 21:21
Logging Service Activator -- Real Time Logging Project
class LogMessageCommand {
String level
String threadName
String application
String message
String hostname
String ipAddress
LocalDateTime messageTime = new LocalDateTime() // this is joda-time
}
@danveloper
danveloper / Config.groovy
Created March 20, 2013 21:22
Atmosphere "base mapping uri" config -- Real Time Logging Project
grails.atmosphere.mappingUri = '/atmosphere/logging'
@danveloper
danveloper / LoggingService.groovy
Created March 20, 2013 21:23
Registering new atmosphere mapping -- Real Time Logging Project
// Registering an application's logging instance either means creating a new mapping for it.
// If a mapping already exists, update its "latest update time" property.
private def registerApplicationInstance(String ipAddress, String hostname, String appName) {
if (!applications[appName]) {
applications[appName] = []
}
def existing = findApplicationObject(appName, ipAddress, hostname)
if (!existing) {
// Register the new application and create a unique mapping for it.
applications[appName] << [ipAddress: ipAddress, hostname: hostname, lastUpdateTime: new LocalDateTime()]
@danveloper
danveloper / gist:5208601
Last active December 15, 2015 05:20
UI Atmosphere Subscription -- Real Time Logging
<!-- ... resources & jquery snipped for brevity ... -->
<atmosphere:resources/>
<r:script>
$(document).ready(function() {
var url = '${createLink(uri:ApplicationHolder.application.config.grails.atmosphere.mappingUri)}';
$.atmosphere.subscribe(url, Logging.router, $.atmosphere.request = {transport:'websocket', fallbackTransport:'streaming'});
...
});
</r:script>
@danveloper
danveloper / index.xml
Created March 20, 2013 21:25
UI Atmosphere Subscription (new logging instance) -- Real Time Logging Project
<!-- ... some rendered code, divs and shit, removed for brevity ... -->
<script>
(function() {
var url = '${createLink(uri: ApplicationHolder.application.config.grails.atmosphere.mappingUri)}/logchannel/${id}/${ip}/${hostname}';
$.atmosphere.subscribe(url, Logging.router, $.atmosphere.request = {transport:'websocket', fallbackTransport:'streaming'});
...
})();
</script>
@danveloper
danveloper / LoggingService.groovy
Last active December 15, 2015 06:09
LoggingService.log - Real Time Logging Project
class LoggingService {
/**
* These two fields represent the atmosphere "config".
*/
static final MAPPING_URI = ApplicationHolder.application.config.grails.atmosphere.mappingUri
static atmosphere = [mapping: MAPPING_URI]
/**
* The {@link LoggingServiceActivator} delegates its messages to this method.
* This method, in turn, broadcasts them to the UI via the atmosphere broadcaster.