23 Ağustos 2023 Çarşamba

Docker ve Artemis

Örnek
Şöyle yaparız
docker run --rm \ -e AMQ_EXTRA_ARGS="--http-host 0.0.0.0 --relax-jolokia" \ -e AMQ_USER=admin \ -e AMQ_PASSWORD=admin \ -p 61616:61616 \ -p 8161:8161 \ --name artemis \
quay.io/artemiscloud/activemq-artemis-broker
Bağlanmak için şöyle yaparız. Kullanıcı adı ve şifre yukarıda belirtiliyor

15 Ağustos 2023 Salı

Docker ve ActiveMQ

Örnek
Şöyle yaparız
> docker run -d --name activemq -p 61616:61616 -p 8161:8161 webcenter/activemq
Daha sonra şu adrese gideriz
Kullanıcı adı : admin Şifre : admin

2 Ağustos 2023 Çarşamba

Java Transaction API - JTA - Distributed Transaction İçindir

Giriş
Açıklaması şöyle
The Java Transaction API (JTA) is one of the APIs defined in the Java Enterprise Edition (Java EE) platform, specifically providing a framework for handling distributed transactions in a consistent and reliable manner.
Açıklaması şöyle
The Java Transaction API consists of three key elements:

UserTransaction interface: This provides the application with the ability to control transaction boundaries programmatically.
TransactionManager interface: It offers more advanced features, like suspending, resuming transactions, and is typically used by the container rather than by the application.
XAResource interface: This is the bridge between the resource manager (like a database) and the transaction manager. It includes methods for associating a resource with a transaction and for transaction completion.
UserTransaction yazısına bakabilirsiniz

JTA UserTransaction Arayüzü

Giriş
Eski kodlarda şu satırı dahil ederiz.
import javax.transaction.UserTransaction;
Şu satırı dahil ederiz
import jakarta.transaction.UserTransaction;
Açıklaması şöyle
UserTransaction interface: This provides the application with the ability to control transaction boundaries programmatically.
Maven
API için şu satırı dahil deriz
<dependency>
  <groupId>javax.transaction</groupId>
  <artifactId>javax.transaction-api</artifactId>
  <version>1.3</version>
</dependency>

Örnek
Şöyle yaparız
@Resource
UserTransaction utx;

public void transferFunds(Account debitAccount, Account creditAccount, double amount) 
throws Exception {
  try {
    utx.begin();
        
    debitAccount.withdraw(amount);
    creditAccount.deposit(amount);

    utx.commit();
  catch (Exception e) {
   utx.rollback();
   throw e;
  }
}

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

Bean Validation @GroupSequence Anotasyonu

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