Skip to content

Add support for configuring non-standard JMS acknowledge modes #37576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Sep 25, 2023

Prior to this commit, spring.jms.listener.acknowledge-mode and
spring.jms.template.acknowledge-mode accepted only a predefined set of
values representing standard JMS acknowledge modes.

This commit adds support for also using arbitrary integer values to
these configuration properties, which allow configuring vendor-specific
JMS acknowledge modes.

Closes #37447


Note that this PR depends on #37500 (which adds support for spring.jms.template.acknowledge-mode).

This PR also wraps up efforts started in #37473 that aim to improve developer experience when working with JMS vendors such as SQS, which provides non-standard acknowledge modes and doesn't support transactions

Prior to this commit, `spring.jms.listener.acknowledge-mode` and
`spring.jms.template.acknowledge-mode` accepted only a predefined set of
values representing standard JMS acknowledge modes.

This commit adds support for also using arbitrary integer values to
these configuration properties, which allow configuring vendor-specific
JMS acknowledge modes.

Closes spring-projectsgh-37447
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 25, 2023
@wilkinsona wilkinsona self-assigned this Sep 27, 2023
@wilkinsona wilkinsona added type: enhancement A general enhancement status: waiting-for-triage An issue we've not yet triaged and removed status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Sep 27, 2023
@wilkinsona
Copy link
Member

Thanks for the PR, @vpavic. I've rebased this on the latest change in main and tried adding a test:

@Test
void testJmsListenerContainerFactoryWithNonStandardAcknowledgeMode() {
	this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
		.withPropertyValues("spring.jms.listener.session.acknowledge-mode=9")
		.run((context) -> {
			DefaultMessageListenerContainer container = getContainer(context, "jmsListenerContainerFactory");
			assertThat(container.getSessionAcknowledgeMode()).isEqualTo(9);
		});
}

It fails:

java.lang.IllegalArgumentException: Only values of acknowledge mode constants allowed
	at org.springframework.util.Assert.isTrue(Assert.java:111)
	at org.springframework.jms.support.JmsAccessor.setSessionAcknowledgeMode(JmsAccessor.java:170)
	at org.springframework.jms.config.AbstractJmsListenerContainerFactory.createListenerContainer(AbstractJmsListenerContainerFactory.java:235)
	at org.springframework.boot.autoconfigure.jms.JmsAutoConfigurationTests.getContainer(JmsAutoConfigurationTests.java:271)
	at org.springframework.boot.autoconfigure.jms.JmsAutoConfigurationTests.lambda$9(JmsAutoConfigurationTests.java:168)
	at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.accept(AbstractApplicationContextRunner.java:434)
	at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.consumeAssertableContext(AbstractApplicationContextRunner.java:363)
	at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.lambda$1(AbstractApplicationContextRunner.java:341)
	at org.springframework.boot.test.util.TestPropertyValues.lambda$5(TestPropertyValues.java:174)
	at org.springframework.boot.test.util.TestPropertyValues.applyToSystemProperties(TestPropertyValues.java:188)
	at org.springframework.boot.test.util.TestPropertyValues.applyToSystemProperties(TestPropertyValues.java:173)
	at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.lambda$0(AbstractApplicationContextRunner.java:341)
	at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.withContextClassLoader(AbstractApplicationContextRunner.java:369)
	at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.run(AbstractApplicationContextRunner.java:340)
	at org.springframework.boot.autoconfigure.jms.JmsAutoConfigurationTests.testJmsListenerContainerFactoryWithNonStandardAcknowledgeMode(JmsAutoConfigurationTests.java:167)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Apologies if I have introduced the problem while rebasing but I don't think I have. It looks to me like further Framework changes are required to support this.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Sep 27, 2023
@vpavic
Copy link
Contributor Author

vpavic commented Sep 27, 2023

After taking a quick look, it appears that this is caused by a regression in Spring Framework introduced in spring-projects/spring-framework@3b8dd0a. Prior to that commit, JmsAccessor#setSessionAcknowledgeMode wasn't constrained to only standard acknowledge modes - I have several Spring Boot 3.1 based projects that are using SQSSession.UNORDERED_ACKNOWLEDGE.

I'll open an issue against Framework shortly.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 27, 2023
@wilkinsona wilkinsona added status: blocked An issue that's blocked on an external project change and removed status: feedback-provided Feedback has been provided labels Sep 27, 2023
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 27, 2023
@vpavic
Copy link
Contributor Author

vpavic commented Sep 27, 2023

Instead of an issue, I've opened spring-projects/spring-framework#31328 to address the regression on the Framework side.

@vpavic
Copy link
Contributor Author

vpavic commented Sep 29, 2023

With spring-projects/spring-framework#31328 merged, I assume this is now unblocked?

@wilkinsona
Copy link
Member

Not quite. We'll move to snapshots next week so it's blocked until then.

@vpavic
Copy link
Contributor Author

vpavic commented Sep 29, 2023

Is this expected to target 3.2? I'm asking because there's no assigned milestone.

@wilkinsona
Copy link
Member

Hopefully, yes, but we'll have to see what time permits. I'll assign it to 3.x for now and we can hopefully pull it forwards.

@wilkinsona wilkinsona added this to the 3.x milestone Sep 29, 2023
@wilkinsona wilkinsona removed the status: blocked An issue that's blocked on an external project change label Oct 9, 2023
wilkinsona pushed a commit to wilkinsona/spring-boot that referenced this pull request Oct 11, 2023
Prior to this commit, `spring.jms.listener.session.acknowledge-mode`
and `spring.jms.template.session.acknowledge-mode` accepted only a
predefined set of values representing standard JMS acknowledge modes.

This commit adds support for also using arbitrary integer values to
these configuration properties, which allows vendor-specific JMS
acknowledge modes to be configured.

See spring-projectsgh-37576
wilkinsona added a commit to wilkinsona/spring-boot that referenced this pull request Oct 11, 2023
@wilkinsona
Copy link
Member

I've pushed my polishing: https://github.com/wilkinsona/spring-boot/tree/gh-37576.

However, I think we may need to take a different approach for a couple of reasons:

  1. By moving away from an enum, we've lost the capabilities of LenientStringToEnumConverterFactory. This means that values like dupsok will no longer work.
  2. By doing the mapping when the property is used rather than when it's bound, the diagnostics won't be so good when the configuration is invalid

I'd like to discuss this with the rest of the team.

@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Oct 11, 2023
@philwebb philwebb removed the for: team-meeting An issue we'd like to discuss as a team to make progress label Oct 11, 2023
wilkinsona added a commit to wilkinsona/spring-boot that referenced this pull request Oct 11, 2023
wilkinsona added a commit to wilkinsona/spring-boot that referenced this pull request Oct 11, 2023
wilkinsona added a commit to wilkinsona/spring-boot that referenced this pull request Oct 11, 2023
@wilkinsona wilkinsona modified the milestones: 3.x, 3.2.x, 3.2.0-RC1 Oct 12, 2023
wilkinsona pushed a commit that referenced this pull request Oct 12, 2023
Prior to this commit, `spring.jms.listener.session.acknowledge-mode`
and `spring.jms.template.session.acknowledge-mode` accepted only a
predefined set of values representing standard JMS acknowledge modes.

This commit adds support for also using arbitrary integer values to
these configuration properties, which allows vendor-specific JMS
acknowledge modes to be configured.

See gh-37576
@vpavic vpavic deleted the gh-37447 branch November 5, 2023 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for configuring non-standard JMS acknowledge modes
4 participants