uebung3
wip
This commit is contained in:
+36
-8
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>de.componentware</groupId>
|
||||
@@ -9,20 +9,40 @@
|
||||
</parent>
|
||||
<artifactId>ejb-client</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb-client-bom</artifactId>
|
||||
<version>39.0.0.Final</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- Abhängigkeit zu den EJB-Interfaces des Server-Moduls -->
|
||||
<!-- Server-Interfaces (Remote-Interface etc.) -->
|
||||
<dependency>
|
||||
<groupId>de.componentware</groupId>
|
||||
<artifactId>ejb-server</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- BOM für alle WildFly EJB-Client Abhängigkeiten -->
|
||||
<!-- Artemis JMS Client (implementation) - must match the Artemis version bundled in WildFly -->
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-jakarta-client</artifactId>
|
||||
<version>2.44.0</version>
|
||||
</dependency>
|
||||
<!-- WildFly Naming Client (Remote JNDI) -->
|
||||
<dependency>
|
||||
<groupId>org.wildfly</groupId>
|
||||
<artifactId>wildfly-ejb-client-bom</artifactId>
|
||||
<version>39.0.0.Final</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
<artifactId>wildfly-naming-client</artifactId>
|
||||
</dependency>
|
||||
<!-- Jakarta Messaging API (JMS 3.1) – macht die JMS-Typen verfügbar -->
|
||||
<dependency>
|
||||
<groupId>jakarta.jms</groupId>
|
||||
<artifactId>jakarta.jms-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
@@ -30,7 +50,15 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<version>3.13.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<classpathScope>runtime</classpathScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -7,8 +7,7 @@ import java.util.Scanner;
|
||||
public class Client {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
"org.wildfly.naming.client.WildFlyInitialContextFactory");
|
||||
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
|
||||
props.setProperty(Context.PROVIDER_URL, "http-remoting://localhost:8080");
|
||||
|
||||
InitialContext ctx = new InitialContext(props);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.example.demo.uebung3.aufgabe13;
|
||||
|
||||
import java.util.Properties;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import jakarta.jms.Connection;
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.Destination;
|
||||
import jakarta.jms.JMSException;
|
||||
import jakarta.jms.MessageProducer;
|
||||
import jakarta.jms.Session;
|
||||
import jakarta.jms.TextMessage;
|
||||
|
||||
public class Client {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
|
||||
props.setProperty(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
|
||||
|
||||
try {
|
||||
InitialContext context = new InitialContext(props);
|
||||
|
||||
// ConnectionFactory und Ziel-Queue ermitteln
|
||||
ConnectionFactory factory = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
|
||||
Destination queue = (Destination) context.lookup("jms/queue/MyQueue");
|
||||
|
||||
// Verbindung und Session aufbauen
|
||||
Connection con = factory.createConnection("guest", "guest");
|
||||
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
con.start();
|
||||
|
||||
// Nachricht erstellen und senden
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
TextMessage message = session.createTextMessage("Hallo-Welt");
|
||||
producer.send(message);
|
||||
|
||||
System.out.println("Nachricht 'Hallo-Welt' in Queue gestellt.");
|
||||
|
||||
// Ressourcen schließen
|
||||
producer.close();
|
||||
session.close();
|
||||
con.close();
|
||||
context.close();
|
||||
} catch (NamingException | JMSException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user