When receiving messages in WebSphere MQ, MQ regards the message as a text message only if the “formatName” message property is set to “MQSTR”. Otherwise, MQ handles the message as a byte message.
Example 1 Sends a text message to WebSphere MQ.
declare @msg varchar(1024) select @msg = 'abc' select msgsend(@msg,'ibm_mq:channel1/TCP/host1(7654)? qmgr=QM,queue=Q1,alter_user=yes',message property "formatName=MQSTR")
Example 2 Receives a text message from WebSphere MQ:
select msgrecv('ibm_mq:channel1/TCP/host1(7654)? qmgr=QM,queue=Q1,alter_user=yes', option 'bufferLength=20000k,timeout=60000', returns varchar(1024))
Exampe 3 Sends a byte message to WebSphere MQ:
declare @msg varbinary(1024) select @msg = 'abc' select msgsend(@msg,'ibm_mq:channel1/TCP/host1(7654)? qmgr=QM,queue=Q1,alter_user=yes')
Example 4 Receives a byte message from WebSphere MQ:
select msgrecv('ibm_mq:channel1/TCP/host1(7654)? qmgr=QM,queue=Q1,alter_user=yes', option 'bufferLength=20000k,timeout=60000', returns varbinary(1024))
Example 5 You can send a byte payload as a text message in WebSphere MQ as long as it is UTF8-encoded. In this example, text message “abc” is being sent based on byte payload 0x616263 because the UTF8 encoding of text “abc” is 0x616263:
declare @msg varbinary(1024) select @msg = 0x616263 select msgsend(@msg,'ibm_mq:channel1/TCP/host1(7654)? qmgr=QM,queue=Q1,alter_user=yes', message property "formatName=MQSTR")