27 Temmuz 2023 Perşembe

ActiveMQ ActiveMQConnectionFactory Sınıfı

Giriş
Şu satırı dahil ederiz
import org.apache.activemq.ActiveMQConnectionFactory;
constructor - brokerUrl
Broker adresini parametre olarak alır

Örnek - tcp
Şöyle yaparız
@Bean
public ConnectionFactory connectionFactory() {
  return new ActiveMQConnectionFactory("tcp://localhost:4444");
}
Örnek
Şöyle yaparız
ActiveMQConnectionFactory cf =
new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false")
Örnek
Şöyle yaparız. Yerel makinede çalıştırır.
import org.apache.activemq.ActiveMQConnectionFactory;
import static org.apache.activemq.ActiveMQConnection.DEFAULT_BROKER_URL;

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(DEFAULT_BROKER_URL);
constructor - user + password + brokerUrl
Örnek
Şöyle yaparız
@Configuration
@EnableJms
public class JmsConfig {

  @Value("${activemq.url}")
  private String brokerUrl;

  @Value("${activemq.user}")
  private String user;

  @Value("${activemq.password}")
  private String password;

  @Bean
  public ActiveMQConnectionFactory connectionFactory() {
    if ("".equals(user)) {
      return new ActiveMQConnectionFactory(brokerUrl);
    }
    return new ActiveMQConnectionFactory(user, password, brokerUrl);
  }
  ...
}
createConnection metodu

ActiveMQ Client Kullanımı

Maven
Örnek - Jakarta
Jakarta isim alanını kullanan ilk sürüm 5.18 sürümü. Şu satırı dahil ederiz
<dependency>
<groupId>jakarta.jms</groupId> <artifactId>jakarta.jms-api</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-client-jakarta</artifactId> <version>5.18.2</version> </dependency>
Örnek
Eğer Javax isim alanını kullanıyorsak şu satırı dahil ederiz
<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>activemq-all</artifactId>
  <version>5.18.2</version>
</dependency>
ActiveMQConnectionFactory veya ActiveMQXAConnectionFactory nesnesi yaratılır

Artemis Server Kullanımı

Maven
Şu satırı dahil ederiz
<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>artemis-server</artifactId>
  <version>2.29.0</version>
</dependency>
Gelen bağımlılıklar şöyle
artemis-jakarta-server
  artemis-commons
  artemis-core-client
  artemis-jakarta-client
  artemis-jakarta-service-extensions
  artemis-journal
  artemis-server
  jakarta-jms-api [provided]
  slf4j-api [provided]
EmbeddedActiveMQ ile sunucu yaratılır

Artemis Client Kullanımı

Maven
Örnek
Şu satırı dahil ederiz
<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>artemis-jakarta-client</artifactId>
  <version>2.29.0</version>
</dependency>
Örnek  - Fat Jar
Şu satırı dahil ederiz
<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>artemis-jakarta-client-all</artifactId>
  <version>2.30.0</version>
</dependency>
ActiveMQConnectionFactory ile sunucuya bağlanılır

23 Temmuz 2023 Pazar

Jakarta EE Servlet Kullanımı

Maven
Örnek
Şu satırı dahil ederiz
<dependency>
<groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> </dependency>
Sınıflar şöyle
Cookie
HttpServletResponse
@WebListener Anotasyonu

21 Temmuz 2023 Cuma

Artemis ActiveMQConnectionFactory Sınıfı

Giriş
Şu satırı dahil ederiz
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
constructor
Şöyle yaparız
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616")

Artemis EmbeddedActiveMQ Sınıfı

Giriş
Şu satırı dahil ederiz
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
Örnek
Şu satırı dahil ederiz
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
Şöyle yaparız
public final class ActiveMQBroker {

  public static final String BROKER_URL = "tcp://localhost:61616";

  private EmbeddedActiveMQ broker;

  ActiveMQBroker() throws Exception {
    ConfigurationImpl configuration = new ConfigurationImpl();
    configuration.setSecurityEnabled(false);
    configuration.setPersistenceEnabled(false);
    configuration.addAcceptorConfiguration("my-acceptor", BROKER_URL);

    broker = new EmbeddedActiveMQ();
    broker.setConfiguration(configuration);
    broker.start();
  }

  public void stop() throws Exception {
    broker.stop();
  }
}

Bean Validation @GroupSequence Anotasyonu

Örnek Elimizde şöyle bir kod olsun public class SampleRequest {   @NotNull   LocalDate startDate;   @NotNull   LocalDate endDate;   @AssertT...