Spring Batch
  1. Spring Batch
  2. BATCH-1219

JmsItemReader and -Writer should check for proper settings on JmsTemplate

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.1
    • Component/s: Infrastructure
    • Labels:
      None

      Description

      I created my own JmsItemReader and -Writer-like classes, before realizing that the framework would probably provide default implementations for these. However, I currently prefer my own implementations, as the framework classes don't perform any checking of required properties on the injected JmsTemplate.
      In my implementation I don't inject JmsOperations but JmsTemplate, which allows me to check the inject template for required settings. For example, I currently have something like this in my reader:

      Assert.isTrue(jmsTemplate.getReceiveTimeout() != JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT,
      "JmsTemplate must have a receive timeout!");
      Assert.isTrue(jmsTemplate.getDefaultDestination() != null || jmsTemplate.getDefaultDestinationName() != null,
      "jmsTemplate must have a defaultDestination or defaultDestinationName!");
      this.jmsTemplate = jmsTemplate;

      Especially something like a receive timeout is very important to set for the reader (or the thread will simply block after processing all messages) but easy to forget. Users might even assume the framework takes care of this for them, esp. since the JavaDoc for the JmsItemReader makes no mention of this! Failing fast greatly improves the usability of these trivial helper classes.

      This requires the use of JmsTemplate instead of JmsOperations. I don't believe this interface adds any real value (any mocking library will allow you to still test the ~Reader and ~Writer), but if you don't want to change this you could simply do an instanceof check before casting and performing the checks.

        Activity

        Hide
        Dave Syer added a comment -

        Thanks. I went with the instanceof option (in the setter).

        Show
        Dave Syer added a comment - Thanks. I went with the instanceof option (in the setter).

          People

          • Assignee:
            Dave Syer
            Reporter:
            Joris Kuipers
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 0.5h
              0.5h
              Remaining:
              Remaining Estimate - 0d
              0d
              Logged:
              Time Spent - 10m Time Not Required
              10m