简体   繁体   中英

How to deploy and run EAR java Program with out Web Interface?

HI I am trying to develop an application (EAR) to deploy it on WebSphere application server.

The goal is after deployment, the program needs to run automatically. There is no Web UI required, how do I achieve that? Below is the code. Its just a simple consumer that listens to kafka topic and prints messages.

//Create java class named "SimpleProducer” public class SimpleConsumer{

public static void main(String[] args) throws Exception {
    /*
     * // Check arguments length value if(args.length == 0){
     * System.out.println("Enter topic name"); return; }
     */
    Logger logger = LoggerFactory.getLogger(SimpleConsumer.class);

    // Assign topicName to string variable
    String topicName = "first_topic";

    // create instance for properties to access producer configs
    Properties props = new Properties();

    // Assign localhost id
    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka165.harishfysx.com:9092");
    props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG , StringDeserializer.class.getName());
    props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-fourth-applicaiton");
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG , "earliest");



    // Create Consumer
    KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
    // Subscribe
    consumer.subscribe(Collections.singleton(topicName));
    //Poll data

    
    while(true) {
        ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
        for (ConsumerRecord<String, String> record :  records) {
            logger.info( "Value :" + record.value());
            logger.info("Offset :" + record.offset());
        }
    }
}

}

您可以创建单例启动 bean - 请参阅此 - https://docs.oracle.com/cd/E19798-01/821-1841/gippq/index.html并将您的应用程序部署为 WebSphere 中的 EJB jar 模块,或包含只是 ejb jar,没有任何 web ui(战争)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM