[Enter feedback here]
Hello,
when I send an message from spring's JmsTemplate message is being automatically created as an XML inside servicebus. However this is creating other issues for us as we are trying to use only application/json type. Is there any option how to configure producer to store messages in service bus as a application/json instead of application/xml?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@lu-cheng , please help to look into this issue, thanks.
Hi @bilak , sorry for the late response. We have been investigating your issue and spring-jms library we used these days, and we found that it's such a pity that spring jms doesn't support custom message header, so we cannot modify messages' content type, which is already defined by jms specification.
Do you guys even know what libraries you use underneath your own libraries?
Again it's a shame that you provide library and your team (even support!!!) doesn't know anything about it :-1:
import java.io.IOException;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.Session;
import org.apache.qpid.jms.message.JmsBytesMessage;
import org.apache.qpid.jms.provider.amqp.message.AmqpJmsMessageFacade;
import org.apache.qpid.proton.amqp.Symbol;
import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
import org.springframework.jms.support.converter.MessageType;
import com.fasterxml.jackson.databind.ObjectWriter;
public class CustomMappingJackson2MessageConverter extends MappingJackson2MessageConverter {
public static final String TYPE_ID_PROPERTY = "_type";
public static final String CONTENT_TYPE = "application/json";
public CustomMappingJackson2MessageConverter() {
this.setTargetType(MessageType.BYTES);
this.setTypeIdPropertyName(TYPE_ID_PROPERTY);
}
@Override
protected BytesMessage mapToBytesMessage(Object object, Session session, ObjectWriter objectWriter)
throws JMSException, IOException {
final BytesMessage message = super.mapToBytesMessage(object, session, objectWriter);
JmsBytesMessage msg = (JmsBytesMessage) message;
AmqpJmsMessageFacade facade = (AmqpJmsMessageFacade) msg.getFacade();
facade.setContentType(Symbol.valueOf(CONTENT_TYPE));
return msg;
}
}
Hi @bilak , I feel quite sorry that due to my personal unfamiliarity with qpid-jms-client, I have blocked you for such a long time. At the beginning I tried to solve it from amqp side, but after seeing the reply of your stackoverflow issue then I gave up and turned to spring jms. Again that's all because of my personal capabilities and I have learnt a lot now.
A good job of you.
Hi @bilak , we now support configuring message converter bean to set content-type, here is the pr and you can wait for our next release.
Hi @bilak , we have published version 3.2.0 of azure-spring-boot-starter-servicebus-jms to Maven, you can refer to https://mvnrepository.com/artifact/com.azure.spring/azure-spring-boot-starter-servicebus-jms/3.2.0.
@yiliuTo and what is the solution in that release? Because in PR above there is nothing that resolves issue, it's still not possible to send message as application/json. You've just removed default jms template but I can't see any documentation nor helper class that will create a jms template with proper configuration.
@bilak , we remove the default jms template and use Spring framework's jms template which can pick up a message converter bean. So in the latest release, you could configure a custom message converter as you need and modify the content-type. Here is the doc.
Most helpful comment
Do you guys even know what libraries you use underneath your own libraries?
Again it's a shame that you provide library and your team (even support!!!) doesn't know anything about it :-1: