Skip to content

JmsClient.sendAndReceive() fails if headers are included #36118

@RenBrand

Description

@RenBrand

Overview

The following example fails with a "No 'defaultDestination' configured"-Exception even if a destination was provided.

public static record Msg(String content) {}
public static record ResponseMsg( String value ) {}

public static ResponseMsg sendAMessageWithHeaderValues(JmsClient jmsClient) {
  Msg msg = new Msg( "myContent");
  Map<String, Object> headers = Map.of( "a", "header-value" );

  return jmsClient.destination("a-simple-queue")
                  .sendAndReceive( msg, headers, ResponseMsg.class );
}

Exception:

java.lang.IllegalStateException: No 'defaultDestination' configured
	at org.springframework.util.Assert.state(Assert.java:80)
	at org.springframework.messaging.core.AbstractMessageSendingTemplate.getRequiredDefaultDestination(AbstractMessageSendingTemplate.java:102)
	at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:93)
	at org.springframework.jms.core.DefaultJmsClient$DefaultOperationSpec.sendAndReceive(DefaultJmsClient.java:206)
    ...

If the headers are omitted like in the following example everything works fine.

public static record Msg(String content) {}
public static record ResponseMsg( String value ) {}

public static ResponseMsg sendAMessageWithHeaderValues(JmsClient jmsClient) {
  Msg msg = new Msg( "myContent");

  return jmsClient.destination("a-simple-queue")
                  .sendAndReceive( msg, ResponseMsg.class );
}

The problem seams to be located in the JmsMessagingTemplate, because it misses to override the method AbstractMessagingTemplate.convertSendAndReceive(Object, Map<String, Object>, Class<T>, MessagePostProcessor) in a similar way as it is done for JmsMessagingTemplate.convertSendAndReceive(Object, Class<T>, MessagePostProcessor). Here the overwritten implementation checks for the "defaultDestination" and uses the "defaultDestinationName" if it is missing. The original version from AbstractMessagingTemplate only uses the "defaultDestination" and never falls back to the "defaultDestinationName", because it doesn't know anything about this property.

Related Issues

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions