채팅이 내가 뭘하려XMPP의 봄 통합 - 내가 듣고 XMPP를 사용하여 메시지를 보낼 봄 부팅에서 서버를 만들려고, XMPP 새로운 오전
의 context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/xmpp
http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd">
<int-xmpp:xmpp-connection
id="xmppConnection"
user="[email protected]"
password="finatel123"
host="192.168.1.201"
port="5222"/>
<int-xmpp:inbound-channel-adapter
id="xmppInboundAdapter"
channel="chatMessageListening"
xmpp-connection="xmppConnection"
auto-startup="true"/>
<int-xmpp:outbound-channel-adapter
id="outboundEventAdapter"
channel="chatMessageSending"
xmpp-connection="xmppConnection"
auto-startup="false">
<poller fixed-rate="5000" max-messages-per-poll="1"/>
</int-xmpp:outbound-channel-adapter>
</beans:beans>
ChatMessageListening.java
public class ChatMessageListening implements MessageChannel {
@Override
public boolean send(Message<?> message) {
MessageHeaders headers = message.getHeaders();
System.out.println("FROM : "+headers.get(XmppHeaders.FROM));
System.out.println("TO : "+headers.get(XmppHeaders.TO));
System.out.println("Time : "+new Date((Long)headers.get("timestamp")));
return true;
}
@Override
public boolean send(Message<?> message, long timeout) {
return true;
}
}
ChatMessageSending.java
public class ChatMessageSending implements PollableChannel {
@Override
public boolean send(Message<?> message) {
return true;
}
@Override
public boolean send(Message<?> message, long timeout) {
return true;
}
@Override
public Message<?> receive() {
return null;
}
@Override
public Message<?> receive(long timeout) {
return null;
}
}
이 구성을 수행하면 ChatMessageListening.send()
방법으로 메시지를 수신 할 수 있습니다.
MessagingTemplate template = new MessagingTemplate();
template.setSendTimeout(5000L);
Message<String> xmppOutboundMsg = MessageBuilder.withPayload("Hello, XMPP!")
.setHeader(XmppHeaders.FROM, "[email protected]")
.setHeader(XmppHeaders.TO, "[email protected]")
.setHeader(XmppHeaders.TYPE, "chat")
.build();
template.setDefaultChannel(new ChatMessageSending());
template.send(xmppOutboundMsg);
을 시도하지만 클라이언트에 전송되지 않고는 ChatMessageSending
에 수신. 내가 뭘 잘못하고 있는지 안내해 줘. 내가 사용해야하는 것.
XMPP 샘플 링크를 제공해 주셔서 감사합니다. 필자는 메시지 수신 및 전송을 위해 인바운드 채널 어댑터와 아웃 바운드 채널 어댑터에 대해 별도의 채널과 별도의 서비스 활성화기를 만들었습니다. –
좋습니다! 따라서 이것을 고려하십시오. http://stackoverflow.com/help/someone-answers –