001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017 018package org.apache.logging.log4j.core.net.mom.jms; 019 020import java.io.BufferedReader; 021import java.io.InputStreamReader; 022import java.nio.charset.Charset; 023 024import org.apache.logging.log4j.core.net.server.JmsServer; 025 026/** 027 * Receives Topic messages that contain LogEvents. This implementation expects that all messages 028 * are serialized log events. 029 */ 030public class JmsTopicReceiver { 031 032 /** 033 * Main startup for the receiver. 034 * @param args The command line arguments. 035 * @throws Exception if an error occurs. 036 */ 037 public static void main(final String[] args) throws Exception { 038 if (args.length != 4) { 039 usage("Wrong number of arguments."); 040 } 041 042 final String tcfBindingName = args[0]; 043 final String topicBindingName = args[1]; 044 final String username = args[2]; 045 final String password = args[3]; 046 final JmsServer server = new JmsServer(tcfBindingName, topicBindingName, username, password); 047 server.start(); 048 049 final Charset enc = Charset.defaultCharset(); 050 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, enc)); 051 // Loop until the word "exit" is typed 052 System.out.println("Type \"exit\" to quit JmsTopicReceiver."); 053 while (true) { 054 final String line = stdin.readLine(); 055 if (line == null || line.equalsIgnoreCase("exit")) { 056 System.out.println("Exiting. Kill the application if it does not exit " 057 + "due to daemon threads."); 058 server.stop(); 059 return; 060 } 061 } 062 } 063 064 private static void usage(final String msg) { 065 System.err.println(msg); 066 System.err.println("Usage: java " + JmsTopicReceiver.class.getName() 067 + " TopicConnectionFactoryBindingName TopicBindingName username password"); 068 System.exit(1); 069 } 070}