grails-routing icon indicating copy to clipboard operation
grails-routing copied to clipboard

Grails Camel Routing Plugin Not recognising sendMessage

Open anixan opened this issue 10 years ago • 8 comments

Hi All,

We have a project that we recently required the use of Camel in. This projects is a Groovy/Grails project and I have installed the Routing 1.4.1 plugin.

I then proceeded to create a new route as specified in the documentation which is shown below:

package some_package

import org.apache.camel.builder.RouteBuilder

class TestRoute extends RouteBuilder {
    def grailsApplication

    @Override
    void configure() {
        def config = grailsApplication?.config

        // example:
         from('seda:input.queue').to('stream:out')

    }
}

Then I proceeded to setup a call to this Route in one of my Controllers using the following 'sendMessage' command:

//Camel Testing
def message = "This is some history"
sendMessage("seda:input.queue", message)

However when typing in the IDE the 'sendMessage' method it does say 'Type Not Found' which says to me maybe I am missing an import of something but according to the documentation this should be available to all Controllers and Services.

I added debug and the code hits the sendMessage line however does not get into the routing method.

Can someone please help with this?

Thanks

anixan avatar Aug 06 '15 11:08 anixan

The documentation clearly says "The plug-in provides a new method, "sendMessage", to all Controllers and Services for sending messages to endpoints." however when I start typing this in InteliJ it does not resolve and is shown as 'Type Not Found'

anixan avatar Aug 06 '15 13:08 anixan

Have you tried any of the provided examples? Which version of grails are you using?

padcom avatar Aug 07 '15 10:08 padcom

Yes the code above I have tried is based on the documentation.

I am using Grails 2.4.3, have a missed some sort of setup step?

I was expecting to be able to see the output in the console in InteliJ but nothing is shown.

anixan avatar Aug 07 '15 12:08 anixan

Hi,

So I installed everything again from scratch and used an older version of InteliJ and the simple example worked great.

Next I tried a more complex example of calling a service, however the app fails on startup, I have put the Service, Route and sendMessage data below:

Route

from("seda:input.queue").filter {
            it.in.body.contains("test")
        }.to("bean:TestService?method=printMsg")

Service

def printMsg(msg){
        println(msg)
    }

sendMessage

def myMessage = "this is a test message"
sendMessage("seda:input.queue", myMessage)

The error I get when running the app is below:

Error 2015-08-07 13:46:46,156 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: groovy.lang.MissingMethodException: No signature of method: org.grails.plugins.routing.processor.PredicateProcessor.to() is applicable for argument types: (java.lang.String) values: [bean:TestService?method=printMsg]
Possible solutions: is(java.lang.Object), any(), use([Ljava.lang.Object;), getAt(java.lang.String), with(groovy.lang.Closure), any(groovy.lang.Closure)
Message: groovy.lang.MissingMethodException: No signature of method: org.grails.plugins.routing.processor.PredicateProcessor.to() is applicable for argument types: (java.lang.String) values: [bean:TestService?method=printMsg]
Possible solutions: is(java.lang.Object), any(), use([Ljava.lang.Object;), getAt(java.lang.String), with(groovy.lang.Closure), any(groovy.lang.Closure)

I hope you can help.

anixan avatar Aug 07 '15 13:08 anixan

Ok so i removed the filter piece and the application loaded.

However when the sendMessage got run I got the following error:

Message: No bean could be found in the registry for: TestService

I then tried to add the bean manually using the following code but still get the same error:

void configure() {
        def config = grailsApplication?.config

        SimpleRegistry registry = new SimpleRegistry();
        registry.put("TestService", new TestService());
        CamelContext context = new DefaultCamelContext(registry);

        from("seda:input.queue").to("bean:TestService?method=printMsg")

    }

anixan avatar Aug 07 '15 16:08 anixan

I have not maintained this plugin for a while now but from the looks of it I'd say it is not compatible with this version of grails. Try an older version 2.0, maybe even 1.x

padcom avatar Aug 07 '15 19:08 padcom

Hi,

I cannot revert the project to a previous version, is there any other way to get the plugin to pickup the Bean for processing?

Thanks

anixan avatar Aug 10 '15 07:08 anixan

Hi,

Ok I got it to work I inspected all beans currently loaded and corrected my call.

This can be closed.

Thanks

anixan avatar Aug 10 '15 08:08 anixan