More than one channel in BlazeDS

2019-05-20 23:30发布

问题:

I am trying to set up a scenario where a Flex application would be able to use resources written in two different web application implementing BlazeDS.

I originally tried to do it by specifying a channel set in my mxml code and then setting this as the channel set of the service in mxml. However, although this worked, I was getting duplicate session errors.

It was suggested in one of the answers to my question linked to above that I could/should see about setting up channels with different endpoints. I guess this means that the Flex app will only be connecting to one service as it sees it but that the service will actually be delivering this service from another location as well.

I tried doing the following in my services-config.xml:

        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>

        <channel-definition id="my-amf2" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://localhost:7001/dataservice1/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>

But I get the following errors in my weblogic console when trying to start up my server.

Could not register endpoint 'my-amf' because its URL, '/messagebroker/amf', is already used by endpoint 'my-amf2'

and

"MessageBrokerServlet" failed to preload on startup in Web application: "/dataservice2". flex.messaging.config.ConfigurationException: Could not register endpoint 'my-amf' because its URL, '/messagebroker/amf', is already used by endpoint 'my-amf2'

and

Unable to set the activation state to true for the application '_appsdir_DataService2_dir'. weblogic.application.ModuleException: [HTTP:101216]Servlet: "MessageBrokerServlet" failed to preload on startup in Web application: "/dataservice2".

I'm guessing that this is because you can only have one channel of class mx.messaging.channels.AMFChannel. Is this correct?

In general, is there a way around any of the problems I'm experiencing? I'm open to different solutions.

I've googled and read for hours and hours but can't find anything about this.

We want to have a common functionality service that is shared amongst all applications and an application specific service that provides services specific to that application.

回答1:

I'll just summarize what we've been discussing so that other readers might benefit.

Let's look closely at the error message:

Could not register endpoint 'my-amf' because its URL, '/messagebroker/amf', is already used by endpoint 'my-amf2'

It speaks of '/messagebroker/amf' and doesn't mention the part of the URL before this, i.e. the part with the port number. From this we can derive that BlazeDS simply ignores this first part when it ascertains that two endpoints are identical or not. As such http://localhost:7001/dataservice1/messagebroker/amf and http://localhost:7002/dataservice2/messagebroker/amf would be considered identical even though they point to a different instance.

quick fix

A simple fix for this issue would be to simply rename the second endpoint after the last forward slash. For instance http://localhost:7001/dataservice1/messagebroker/amf2 should already do the trick. I don't think there is anything else you need to worry about since the MessageBroker servlet has a mapping with a wildcard after this last slash (/messagebroker/*) which will route any address formatted like this to the right servlet.

but why?

Perhaps you should reconsider why you're trying to do this. The reason that BlazeDS only checks the last part is that the developers probably simply didn't think of the fact that someone would actually try to point an endpoint to a different instance. Furthermore in your setup this other instance already has the same channel definition. You could simply connect to that channel so there is no need for this routing from the first instance. I have no idea what you're trying to achieve so all I can tell you is that you're probably approaching it from the wrong angle.



回答2:

A bit out of topic but did you consider using GraniteDS? It would give you much better real-time messaging performance/scalability with its support of WebLogic's asynchronous servlets (see here and here). Connecting to two different webapps shouldn't be a problem as well, since the two messaging contexts (channel definitions, etc.) would be saved in separate servlet contexts.



标签: flex blazeds