concept LocalRunner in category apache pulsar

appears as: LocalRunner
Apache Pulsar in Action

This is an excerpt from Manning's book Apache Pulsar in Action.

Typically, you would run the LocalRunner test from inside your IDE in order to attach a debugger and step through the function code in order to identify and resolve any errors you have encountered. However, in this scenario I want run the LocalRunner test using the command line. Therefore, I must first bundle the test class that is located under the chapter4/src/main/test folder of the GitHub repo associated with this book into a jar file along with all the necessary dependencies, including the LocalRunner class by running the maven assemble command. Once that is complete, we can start the LocalRunner commands as shown in Listing 4.12.

Next, I need to follow the steps shown in Listing 6.7 again, in order launch a new container based on the updated Docker image, ssh into the container, and run the publish-credentials.sh script inside the newly launched bash session in order to make these client certificates available to me in the ${HOME}/exchange folder on my local machine. For instance, the certificate file admin.cert.pem, and the associated private key file admin-pk8.pem can now be used together to authenticate to the Pulsar standalone instance. Next, I will attempt to use TLS authentication by using the Java program shown in Listing 6.14, which is available in the GitHub repo associated with this book.

Listing 6.14 Authenticating with TLS Client Certificates
import org.apache.pulsar.client.api.*;
 
public class TlsAuthClient {
  public static void main(String[] args) throws PulsarClientException {
    final String AUTH = "org.apache.pulsar.client.impl.auth.AuthenticationTls";
    final String HOME = "/Users/david/exchange";
    final String TOPIC = "persistent://public/default/test-topic";
        
    PulsarClient client = PulsarClient.builder()
        .serviceUrl("pulsar+ssl://localhost:6651/")    #A
        .tlsTrustCertsFilePath(HOME + "/ca.cert.pem")    #B
        .authentication(AUTH,    #C
            "tlsCertFile:" + HOME + "/admin.cert.pem," +    #D 
            "tlsKeyFile:" + HOME + "/admin-pk8.pem")    #E
        .build();
 
    Producer<byte[]> producer = 
      client.newProducer().topic(TOPIC).create();
        
    for (int idx = 0; idx < 100; idx++) {
      producer.send("Hello TLS Auth".getBytes());
    }    
    System.exit(0);
  }
}

#A Use the pulsar+ssl protocol, failure to do so will result in a connection failure.

#B The location of the file containing the trusted TLS certificates