Adam Bien's Weblog

You searched this site for "eclipse rcp". 271 entries found.

You can also try this same search on Google.

Showing 1 - 10 of total 271 search results

« Previous page | Main | Next page »

From Jakarta EE ManagedExecutorService to MicroProfile ManagedExecutor

In Java EE / Jakarta EE environments a ManagedExecutorService instance is injectable via the @Resource annotation:


import javax.enterprise.concurrent.ManagedExecutorService;
public class EventSource {

    
    @Resource
    ManagedExecutorService threadPool;
(...)
}

[code from: Java EE 8: Sending asynchronous CDI 2.0 events with ManagedExecutorService]

In pure MicroProfile environments these API is not available but can be replaced with ManagedExecutor from MicroProfile Context Propagation:


import org.eclipse.microprofile.context.ManagedExecutor;
public class EventSource {

    @Inject
    ManagedExecutor executor;
}

Both injected instances are inheriting from ExecutorService. Migration from javax.enterprise.concurrent.ManagedExecutorService to org.eclipse.microprofile.context.ManagedExecutor should be matter of replacing @Resource with @Inject, renaming the injected classes and fixing the imports.

Quarkus, MicroProfile Metrics and micrometer.io

Quarkus recommends micrometer.io metrics. What is the difference to microprofile.io metrics? In this screencast I'm starting with MicroProfile metrics registry and then migrating to micrometer.io MeterRegistry:

MicroProfile 3.3: Links to Specs and JavaDoc

MicroProfile also relies on Java EE 8 APIs. The specs from the opensource Java EE 8 counterpart: Jakarta EE 8 are easier (directly) accessible:

Emitting JAX-RS Messages into MicroProfile Reactive Messaging Channels

Reactive Messaging for MicroProfile API allows mapping of method's parameters and return values to virtual channels:


import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.eclipse.microprofile.reactive.messaging.Outgoing;

public class HelloListener {

    @Incoming("hello")
    @Outgoing("confirmed")
    public String onHello(String hello) {
        return "confirmed: " + hello;
    }
}    

Messages consumed by Jakarta RESTful Web Services / Java API for RESTful Web Services can be ingested into the system with the injected Emitter qualified with the @Channel annotation.

After sending the String to the Emitter, the message becomes available in the channel and can be consumed as method parameter or sent to Kafka topic:


import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;

@Path("/hello")
public class HelloResource {

    @Inject
    @Channel("hello")
    Emitter<String> emitter;

    @POST
    @Consumes(MediaType.TEXT_PLAIN)
    public void forward(String message) {
        emitter.send(message);
    }
}    

See it in action, and from scratch in 7 minutes:

JAX-RS API Documentation: Reasonable Practices

Jakarta RESTful Web Services (JAX-RS) / MicroProfile OpenAPI documentation ideas from DevNation Day 2020 conference (0.5 hours):

Jakarta EE, MicroProfile and the iPhone Problem--airhacks.fm podcast episode

Subscribe to airhacks.fm podcast via: spotify| iTunes| RSS

The #94 airhacks.fm episode with Kevin Sutter (@kwsutter) about:
Jakarta EE 9 features, Jakarta EE / MicroProfile dynamics, Eclipse Transformer and MicroProfile platform.
is available for

Microscopic Services and The Jakarta EE 9 Earth Quake--an airhacks.fm podcast

Subscribe to airhacks.fm podcast via: spotify| iTunes| RSS

The #84 airhacks.fm episode with Markus Karg (@mkarg) about:
JAX-RS vs. Jersey, hundreds of microscopic services, long term planning and maintainability, API design, "Contract First Design", Jakarta EE and Eclipse Foundation
is available for download.

Blackbox System Tests with Quarkus and MicroProfile REST Client

To System Test test a JAX-RS service as a blackbox:


@Path("/hello")
public class HelloResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "hello";
    }
}    

A dedicated quarkus project with installed MicroProfile REST Client extension (quarkus-rest-client) can be used as a testbed.

A proxy interface:


import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient(baseUri = "http://localhost:8080")
public interface HelloResource {

    @GET
    @Path("hello")
    @Produces(MediaType.TEXT_PLAIN)
    String content();    
}    

is injectable directly into the system test:


import static org.junit.jupiter.api.Assertions.assertEquals;
import javax.inject.Inject;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class HelloResourceTest {

    @Inject
    @RestClient
    HelloResource resource;

    @Test
    public void hello() {
        String content = resource.content();
        System.out.println(content);
        assertEquals(content,"hello");
    }
    
}    

See it live and from scratch:

Injecting List of Strings with MicroProfile Config

A comma-separated String in microprofile-config.properties:


messages=hello,bye

...can be injected as a List of Strings (other types are injectable as well):

import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("messages")
public class MessagesResource {

    @Inject
    @ConfigProperty(name = "messages")
    List<String> messages;    

    @GET
    public List<String> messages() {
        return this.messages;
    }
}

The following command: curl -i localhost:8080/[THIN_WAR_NAME]/resources/messages prints: ["hello","bye"]

The 4kB ThinWAR project was created with Jakarta EE Essentials Archetype and deployed with: wad.sh in 1.9s

Using Jakarta Server Pages (JSP)s For Web Component Generation / Configuration

JavaScript can be pre-generated on the backend and delivered as static content with JSPs. Jakarta Server Pages (JSP) are used in this screencast to configure a stage-dependent URI in a Web Component / Custom Element defined with MicroProfile Config and exposed via CDI:

The ThinWAR project was created with Jakarta EE Essentials Archetype, the 216kB ThinWAR (JS dependencies included) was built and deployed to Payara 5.193 #badassfish with: wad.sh in 3.2s

...the last 150 posts
...the last 10 comments
License