Announcement Announcement Module
Collapse
No announcement yet.
Bundle publishing two pub-sub chanels as OSgi service Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bundle publishing two pub-sub chanels as OSgi service

    I have gone through the follwoing very interesting blog

    http://blog.springsource.com/2009/02...-on-dm-server/

    but did come across a question.

    If my bundle has two pub-sub channels defined ,then according to the blog i expose it as a OSgi service as follows

    <osgi:service id="Channel1" ref="announcements1"
    interface="org.springframework.integration.channel .SubscribableChannel" />

    <osgi:service id="Channel2" ref="announcements2"
    interface="org.springframework.integration.channel .SubscribableChannel" />



    Now assume i have another bundle B , requiring to import both these services

    HOw does bundle B have it now ?

    Since both are implementing teh same interface how can bundle B differentiate between these two services ?


    1. Does bundle B need to accept it as a list of services ?

    2. Or should I add some extra info on the publishing side and use OSgi filter to get teh desired service on bundle B ?

    3. Or should i be creating a gateway(proxy) giving another interface ,and use this interface to collect the service on the receiving side ?

  • #2
    Glad you found these samples useful and yes the issue you are describing is very common in OSGi.
    So here is what you can do:
    On the publishing side you export service with extra properties that will allow you to uniquely identify it in the future:
    Code:
    <osgi:service id="inboundService" ref="inboundChannel"
    		interface="org.springframework.integration.channel.SubscribableChannel">
    		<osgi:service-properties>
    			<entry key="service.name" value="channelA" />
    		</osgi:service-properties>
    </osgi:service>
    And then on the receiving side (as you mentioned) you can filter via filter attribute of service reference:
    Code:
    <osgi:reference id="filesIn"
    			interface="org.springframework.integration.channel.SubscribableChannel"
                            filter="(&(service.name=channelA))"/>
    Hope that helps

    Comment


    • #3
      Thanks a Lot oleg zhurakousky .

      That confirmed my doubt.

      Will creating the gateway proxy also work ?(option 3 in my question)

      Since i have to give one more interface for gateway , cant i collect the service using this unique interface ?

      Comment


      • #4
        The gateway option also works. I think it would even be preferable in most cases, first because that decouples one bundle from Spring Integration, second because it avoids requiring hardcoded strings on both sides.

        Another thing to consider is to use a single publish subscribe channel and selectors in the receiving bundles to determine which message is handled there.

        Let's say it's a tricky issue that I've tried hard to avoid in the blog.

        Comment


        • #5
          Hi,

          I am trying to use filter in osgi-context.xml of bundle B as mentioned above but it is throwing an error as filter not found + beans:description is required for "entity" defined in osgi-context.xml of bundle A. Code is as below:

          Bundle A:
          osgi-context.xml
          <beans:beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:osgi="http://www.springframework.org/schema/osgi"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
          http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

          <service id="dataSourceMain" ref="dataSource"
          interface="javax.sql.DataSource">
          <service-properties>
          <entry key="jdbcDS" value="main"/>
          </service-properties>
          </service>
          </beans:beans>

          Bundle B
          osgi-context.xml

          <reference id="dataSourceMain" interface="javax.sql.DataSource" filter="(&(jdbcDS=main))"/>

          Please help me to solve these namespace + filter related errors.

          Thanks,
          DK

          Comment


          • #6
            I see that you have a version for the Spring namespace, but not for the osgi namespace. Also you're using a prefix (beans) where beans is the default namespace, and you're not using a prefix for osgi, where you have not defined that as the default namespace. Use code completion to see if you got things right. Also, use the code tags to avoid being funny in your code samples

            Comment


            • #7
              Hi,

              Sorry for putting syntax error probs...

              I was able to solve entity problem by adding beans:entity prefix to it.

              But regarding filter attribute, it did not work with & so i tried without it and it works fine... as: filter=(jdbcDS=main)

              Thanks for your support.

              @ DK

              Comment

              Working...
              X