Announcement Announcement Module
No announcement yet.
Bundle publishing two pub-sub chanels as OSgi service Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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

    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=" .SubscribableChannel" />

    <osgi:service id="Channel2" ref="announcements2"
    interface=" .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:
    <osgi:service id="inboundService" ref="inboundChannel"
    			<entry key="" value="channelA" />
    And then on the receiving side (as you mentioned) you can filter via filter attribute of service reference:
    <osgi:reference id="filesIn"
    Hope that helps


    • #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 ?


      • #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.


        • #5

          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:
          <beans:beans xmlns=""

          <service id="dataSourceMain" ref="dataSource"
          <entry key="jdbcDS" value="main"/>

          Bundle B

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

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



          • #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


            • #7

              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