나는 activemq를 처음 사용합니다. activeMQ에서 주제를 만들고 있습니다. mqtt를 통해 데이터를 게시하고 있습니다.
mosquitto_pub -d -t testTopic -m "test message"
하지만 오류 메시지가 나타납니다.
오류 : 메시지가 예상 된 유형의 TextMessage가 아닙니다.
이것은 내 코드입니다
public void onMessage(Message message) {
if (message instanceof TextMessage) {
}
else
{
logger.error("Message is not of expected type TextMessage.");
}
}
실제 문제는 무엇입니까? . 그러나 iam은 http를 통해 동일한 주제로 데이터를 성공적으로 보냅니다.
어떤 생각 ... ???
ActiveMQ Spring 소비자에서 http 메시지는 텍스트 메시지의 유형이고 mqtt 메시지는 BytesMessage의 유형입니다. 코드를 추가하기 때문에
if (message instanceof BytesMessage) {
BytesMessage bm = (BytesMessage) message;
byte data[];
data = new byte[(int) bm.getBodyLength()];
bm.readBytes(data);
msgText = new String(data);
System.out.println("Message String = "+msgText);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다