Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output tcp server return repeat message #2181

Closed
binlaniua opened this issue Dec 5, 2014 · 2 comments
Closed

output tcp server return repeat message #2181

binlaniua opened this issue Dec 5, 2014 · 2 comments

Comments

@binlaniua
Copy link

new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Socket socket = new Socket("xx", xx);
                    BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    String line = null;
                    while((line = reader.readLine()) != null){
                        System.out.println("thread one: " +line);
                    }
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Socket socket = new Socket("xx", xx);
                    BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    String line = null;
                    while((line = reader.readLine()) != null){
                        System.out.println("thread two: " +line);
                    }
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();

the logstash config

input {

    file {
        path => "xx/access.log"
        type => "web_nginx_access"
    }

}


output {

    tcp {
        host => "xx"
        port => xx
        mode => "server"
    }
}

when i access the nginx website, the console print

thread one: {"message":"xx|-|[05/Dec/2014:09:16:49 +0800]|GET / HTTP/1.1|304|0|-|Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36|-|0.000|530|-","@version":"1","@timestamp":"2014-12-05T01:16:50.064Z","type":"web_nginx_access","host":"lin-22-36","path":"xx/access.log"}
thread two: {"message":"xx|-|[05/Dec/2014:09:16:49 +0800]|GET / HTTP/1.1|304|0|-|Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36|-|0.000|530|-","@version":"1","@timestamp":"2014-12-05T01:16:50.064Z","type":"web_nginx_access","host":"lin-22-36","path":"xx/access.log"}

i want the logstash each message to one client, not all.. how can i do..

@binlaniua
Copy link
Author

i modify the tcp.rb

@codec.on_event do |payload|
        #@client_threads.each do |client_thread|
        #  client_thread[:client].write(payload)
        #end

        #
        if @client_threads.length != 0
          #
          if @client_index > @client_threads.length - 1
            @client_index = 0
          end

          @client_threads[@client_index][:client].write(payload)
          @client_index += 1
        end

        @client_threads.reject! {|t| !t.alive? }
      end

@jordansissel
Copy link
Contributor

For Logstash 1.5.0, we've moved all plugins to individual repositories, so I have moved this issue to logstash-plugins/logstash-output-tcp#7. Let's continue the discussion there! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants