19 Nisan 2017 Çarşamba

@Publisher Anotasyonu

Giriş
Spring Integration projesine ait bir sınıftır. Metodun döndürdüğü sonucu belirtilen channel'a yazar.

Kullanım
Şöyle yaparız.
@Publisher(channel = "amqpOutboundChannel")
public String send() {
  return myString;
}

6 Nisan 2017 Perşembe

DefaultFtpSessionFactory Sınıfı

Giriş
Bu sınıf Spring Integration projesine ait.

constructor
Şöyle yaparız.
DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
setHost metodu
Şöyle yaparız.
sf.setHost(remotehost);
setPassword metodu
Şöyle yaparız.
sf.setPassword(remotepassword);
setPort metodu
Şöyle yaparız.
sf.setPort(remoteport);
setUsername metodu
Şöyle yaparız.
sf.setUsername(remoteuser);

1 Nisan 2017 Cumartesi

MessageChannel Arayüzü

Giriş
Şu satırı dahil ederiz.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
Tanımlama
Bir channel tanımlar ve JMS kuyruğunu ilişkilendiririz. Şöyle yaparız.
<!-- OUTBOUND settings -->
<int:channel id="senderChannel" />

<int-jms:outbound-channel-adapter id="jmsOut" destination="outQueue"
  channel="senderChannel"/>
JMS kuyruğu şöyledir
<bean id="outQueue" class="com.ibm.mq.jms.MQQueue" depends-on="connectionFactory">
  <constructor-arg index="0" value="*****" />
  <constructor-arg index="1" value="******" />
</bean>
Kuyruğa bağlanmak için ayarlar şöyledir.
<!-- Factory Defintions -->
<bean id="connectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
  <property name="transportType" value="1" />
  <property name="queueManager" value="****" />
  <property name="hostName" value="******" />
  <property name="port" value="****" />
  <property name="channel" value="******" />
</bean>
Bu sınıf ile alakası yok ancak örnek olsun diye not alıyorum. Mesajları okumak için şöyle yaparız.
<!-- INBOUND settings -->

<int:channel id="recieverChannel" />    

<int-jms:message-driven-channel-adapter id="jmsIn" destination="inQueue"
  channel="recieverChannel" extract-payload="false" />

<int:service-activator input-channel="recieverChannel" ref="messageListener"
  method="processMessage" />
Okuyan sınıf için şöyle yaparız.
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;

public class MessageListener {

  public void processMessage(Message message) {

    if (message instanceof TextMessage) {
      TextMessage txtmsg = (TextMessage) message;

      try {
         System.out.println(txtmsg.getText());
      } catch (JMSException e) {
        ...
      }
    }
  }
}
send metodu
Elimizde şu nesne olsun
@Autowired
MessageChannel senderChannel;
Şöyle yaparız.
String message = ...;

senderChannel.send(MessageBuilder.withPayload(message).build());