Last updated by
2 years ago
Page: Messaging Integration, Version:2
Messaging Integration
Grails needs to provide a universal messaging system not just something specific to e-mail, although this is clearly important. Rather than introducing two concepts that are essentially the same (email and messaging) they need to be unified into a single concept to avoid duplication of effort.Asynchronous messaging essentially defines the concept of a topic and subscribers and publishers to a topic.Publishers
A publisher is simply a groovy class that follows the convention *Publisher. By default the first part of the name defines the topic it is publishing to:class ExamplePublisher { def sendX() {
return [modelObject:"blah"]
}
}def sendXToTopicName() {
return [mnodelObject:"blah"]
}def topic = "another"Subscribers
A subscriber is an object the receives messaging notifications. They listen to a "topic" in the same way publishers publish to a topic. For example:class ExampleSubscriber { def onMessage(ctx) { }
}Topics
Topics can vary in what they do and achieve. A topic could define an email server to send and listen for new e-mails to and from. Thus allowing the publish and subscribe of email. Alternatively it could be configured as a JMS topic for messaging. Topics will be configured in the ApplicationConfig.groovy file as follows:class ApplicationConfig {
def topics = {
example(type:EMAIL) {
server = "localhost"
port = 3434
// etc
}
}
}