Announcement Announcement Module
Collapse
No announcement yet.
PriorityQueue example needed Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PriorityQueue example needed

    I have a scenario like I receive two types of
    requests
    1. process 50K emails with low priority
    2. process 1 email with high priority

    when I receive single email i need to process that message with high priority.

    Can some body provide me sample code?

  • #2
    Hi,

    I have a quick example over at GitHub that provides a simple PriorityChannel use-case.

    https://github.com/ghillert/spring-i...hannel-example

    The important part is that you need to set the priority of the message (*) e.g. using a header enricher:

    Code:
    	<int:header-enricher id="setHighPrio" input-channel="highPrio" output-channel="priority-channel">
    	    <int:priority value="10"/>
    	</int:header-enricher>
    and combine that with a priority queue channel:

    Code:
    	<int:channel id="priority-channel">
    	    <int:priority-queue/>
    	</int:channel>
    I hope this helps.

    Cheers,

    Gunnar

    (*) Using the message priority is probably the most common use case, however if you need some super-custom prioritization strategy you can provide your own "comparator" to the "priority-queue":

    Code:
    <int:priority-queue comparator=""/>
    For slightly more details see: http://static.springsource.org/sprin...mplementations

    Comment


    • #3
      FYI - The current xml schema (Spring Integration 2.0.5) still allows for using enumerations when defining the message priority in a header enricher ("HIGHEST", "HIGH", "NORMAL", "LOW", "LOWEST"). This needs to be removed and I created the following Jira: https://jira.springsource.org/browse/INT-1986

      Please use Integer values only.

      Comment


      • #4
        Thanks Ghillert,

        I implemented priority value in my code but the message was not processed as priority, it processed only after all the messages in queue have done.
        here I'm adding my context file code

        <int:gateway id="cmGateway" default-request-channel="cmGatewayChannel" service-interface = "org.tgslc.correspondence.integration.gateway.Corr espondenceGateWay" />

        <int:channel id="cmGatewayChannel"/>

        <int:router input-channel="cmGatewayChannel" default-output-channel="lowPriorityChannel" ref="priorityRouter"/>

        <int:channel id="priorityChannel" />
        <int:chain id="splitPriorityCMChain" input-channel="priorityChannel" output-channel="singleCMRecordProducer">
        <int:splitter/>
        <int:header-enricher>
        <int:error-channel ref="failedMessage" />
        <int:header name="CORRESPONDENCE_ID" expression="payload?.dataSetId"/>
        <int:header name="CORRESPONDENCE_TYPE" expression="payload?.messageType"/>
        <int: priority value="1"/>
        </int:header-enricher>
        </int:chain>

        <int:channel id="lowPriorityChannel" />

        <int:chain id="splitCMChain" input-channel="lowPriorityChannel" output-channel="singleCMRecordProducer">
        <int:splitter/>
        <int:header-enricher>
        <int:error-channel ref="failedMessage" />
        <int:header name="CORRESPONDENCE_ID" expression="payload?.dataSetId"/>
        <int:header name="CORRESPONDENCE_TYPE" expression="payload?.messageType"/>
        </int:header-enricher>
        </int:chain>

        <int:channel id = "singleCMRecordProducer" >
        <int: priority-queue capacity="100"/>
        </int:channel>

        <int-jms:outbound-channel-adapter channel="singleCMRecordProducer" destination="ProcessCorrespondenceQueue" />
        <int-jms:inbound-channel-adapter channel="singleCMRecordConsumer" destination="ProcessCorrespondenceQueue" extract-payload="false" >
        <int: poller max-messages-per-poll="100">
        <int:interval-trigger interval="2" time-unit="SECONDS" />
        </int: poller>
        </int-jms:inbound-channel-adapter>
        <int:channel id = "singleCMRecordConsumer" />

        <int:service-activator input-channel="singleCMRecordConsumer" ref="recipientServiceActivator" method="processEmail" output-channel="tranformEmailChannel"/>
        <int:channel id="tranformEmailChannel" />
        <int:transformer input-channel="tranformEmailChannel" output-channel="emailChannel" ref="emailTransformer" />
        <int:channel id="emailChannel" />

        <int-mail:outbound-channel-adapter id="emailOut" channel="emailChannel" mail-sender="mailSender" />


        PriorityRouter.java:
        @MessageEndpoint
        public class PriorityRouter {

        public String determinePriority(List<CorrespondenceDataView> corrDatViewList){
        if (corrDatViewList.size()==1){
        return "priorityChannel";
        }
        return "lowPriorityChannel";
        }
        }

        Comment


        • #5
          Originally posted by ghillert View Post
          Hi,

          I have a quick example over at GitHub that provides a simple PriorityChannel use-case.

          https://github.com/ghillert/spring-i...hannel-example

          The important part is that you need to set the priority of the message (*) e.g. using a header enricher:

          Code:
          	<int:header-enricher id="setHighPrio" input-channel="highPrio" output-channel="priority-channel">
          	    <int:priority value="10"/>
          	</int:header-enricher>
          and combine that with a priority queue channel:

          Code:
          	<int:channel id="priority-channel">
          	    <int:priority-queue/>
          	</int:channel>
          I hope this helps.

          Cheers,

          Gunnar

          (*) Using the message priority is probably the most common use case, however if you need some super-custom prioritization strategy you can provide your own "comparator" to the "priority-queue":

          Code:
          <int:priority-queue comparator=""/>
          For slightly more details see: http://static.springsource.org/sprin...mplementations
          Thank you sir may I answered a question Bali always running.

          Comment

          Working...
          X