Announcement Announcement Module
Collapse
No announcement yet.
How to use SPEL & ReloadableResourceBundleExpressionSource in this particular case? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use SPEL & ReloadableResourceBundleExpressionSource in this particular case?

    Hello,
    I hope somebody could help me to solve this problem in optimal way.
    I need to do the following in my message endpoint (can be transformer or service activator):
    Having a payload of type Transaction as input with fields:
    Code:
    String customerName;
    String customerNumber;
    String status;
    and ReloadableResourceBundleExpressionSource configured (since I need to allow changing values in properties file dynamically) looking like:
    Code:
    from=123456
    to=payload.customerAddress
    content=Hi payload.customerName how are you?
    update=payload.status="done"
    I need to:
    1. create a Map<String, String> httpCallMap which is sent to output channel,
    with the following keys:
    Code:
    String from; 
    String to;
    String content;
    with the values retrieved from expressionSource (my.properties file):

    2. Check if content is specified. If not, I should discard the message.
    3. Update the status of my payload with value from expression source.


    I spent some time browsing through SPEL examples, test cases and documentation (both Spring Core and Spring Integration), but couldn't find the answers to the following questions:

    1. Is it possible to specify more than one expression key in SI component (transformer or service activator)
    2. Alternatively, is it possible to have multiple SPEL expressions pecified for one key, divided with semicolon or in some other way, so these expressions are executed in sequence?
    3. How can I check if a key in my expressionSource file has a value?
    4. And lastly, what would be the best way to implement integration flow?

    Thanks in advance,
    Milan

  • #2
    No, you can only provide a single expression.
    Remember, every EIP component must be well defined and with the designated purpose. For example you may have a service that computes a TAX Rate based on the State value retrieved from the Message Header. This is the example of a well defined service.
    What you seem to be asking (unless I misunderstood you) is if you can have multiple expressions which would allow your service to perform multiple operations. That to me would mean different services.

    As far as checking "if content is specified. If not, I should discard the message." - Message Filter would be the most appropriate component to take care of the job of discarding Message based on the filtering criteria and would require no implementation on your end. A simple SpEL expression would do.
    Assuming Map is a payload of the message:
    Code:
    <int:filter input-channel="inChannel" output-channel="outChannel" expression="payload['content'] != null"/>

    Comment


    • #3
      Hi Oleg, thanks for reply.

      What you seem to be asking (unless I misunderstood you) is if you can have multiple expressions which would allow your service to perform multiple operations. That to me would mean different services.
      True, but I am updating the same object, and thought that would be good if I can do it in single MessageHandler instead of having one MessageHandler per property.

      best,
      Milan

      Comment


      • #4
        that would be good if I can do it in single MessageHandler
        I don't think i agree.
        You basically talking about a sequence of operations that needs to be performed on an Object (which could be a payload of a Message). In Messaging Architectures each operation of some significance is tied to an Messaging Endpoint in a 1:1 relationship. If you need to do several things and you believe they are too granular to be incorporated in an independent endpoint then simply have a POJO based service-activator and write you custom java code to do what is required. Is that what you are trying to do?

        Comment


        • #5
          Code:
          then simply have a POJO based service-activator and write you custom java code to do what is required. Is that what you are trying to do?
          Yes, but I would also like to use benefits of reloadable SPEL expressions.

          Comment


          • #6
            SpEL would probably not be the best thing for your use case since each SpEL expression meant to bring an element of dynamics for a simple evaluation logic (one line, single instruction kind of logic) which is not what you are looking for anyway.
            If I understand you correctly what you are looking for is to script the sequence of fine-grained processing steps BUT the logic for such steps should be dynamically updatable without restarting the Application Context.

            Fortunately we do have support for it via Spring Integration Groovy support where you can provide refresh-check-delay attribute which will check if the groovy script you pointing too was updated.

            Here is the simple configuration:

            Code:
            <service-activator input-channel="inChannel" output-channel="outChannel">
            	<groovy:script location="org/foo/bar/SomeGroovyScript.groovy" refresh-delay-check="10000"/>
            </service-activator>
            In the above the script will be cached, but also checked every 10 seconds and reloaded if it was changed.

            Comment

            Working...
            X