Project

General

Profile

jaxmpp 3.2 with nginx connections

w xy
Added 4 months ago

Now, there is an mistake occurred in the connection between jaxmpp and tigase via nginx proxy.

port: nginx port(8088) -> tigase port(5222)

ConnectionConfiguration configuration = jaxmpp.getConnectionConfiguration();
        configuration.setDomain(xmppConfig.getServerName());
        configuration.setPort(xmppConfig.getPort());
        configuration.setServer(xmppConfig.getHost());
        configuration.setUserJID(this.userJid(username));
        configuration.setUserPassword(Md5Util.md5Hex(username));
        configuration.setResource(xmppConfig.getResource());
        configuration.setDisableTLS(true);
        configuration.setConnectionType(ConnectionConfiguration.ConnectionType.socket);

Error: can not create socket, connection rejection.


Replies (11)

Added by Wojciech Kapcia TigaseTeam 4 months ago

Are you able to open regular TCP connection to tigase on nginx port? (i.e. telnet <nginx_hostname> 8080)?

Added by w xy 3 months ago

Yes, there are 15 connections with nginx, some would make mistakes : can not create sock.

But, when i stoped one of the two tigases, it works well.

Added by Wojciech Kapcia TigaseTeam 3 months ago

Do you configure any kind of stickyness in nginx? With the socket connection type this shouldn't matter, but it's possible that see-other-host mechanism is triggered and some of your clients are redirected to the other node with the internal IP, and when the client tries to connect to it it fails -- it would be better if you could provided detailed logs.

You could also try disabling see-other-host mechanism - please see Tigase Load Balancing for details.

Added by w xy 3 months ago

I found some problem with debugging, like this picture.

nginx port--> 8042, tigase cluster , their port 5222, so cannot create socket.

(1)

Added by w xy 3 months ago

nginx.conf:

stream{
        log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';


        access_log logs/tcp-access.log proxy;
        open_log_file_cache off;
                upstream tigase{
#                       hash $remote_addr consistent;
                        server xmpp.server.10:5222;
                        server xmpp.server.11:5222;
                }



                server{
                        listen 8042;
                        #proxy_connect_timeout 10s;#设置连接超时时间
                        #proxy_timeout 30s;#设置代理超时时间
                        proxy_pass tigase;
                }

}

Added by w xy 3 months ago

w xy wrote:

nginx.conf:

`stream{
log_format proxy '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

    access_log logs/tcp-access.log proxy;
    open_log_file_cache off;
            upstream tigase{

                    server xmpp.server.10:5222;
                    server xmpp.server.11:5222;
            }



            server{
                    listen 8042;
                    #proxy_connect_timeout 10s;#设置连接超时时间
                    #proxy_timeout 30s;#设置代理超时时间
                    proxy_pass tigase;
            }

}`

Added by w xy 3 months ago

remove hash $remote_addr consistent;

Added by w xy 3 months ago

tigase 8.0

Added by w xy 3 months ago

c2s {
    seeOtherHost {class: none}
    'urn:xmpp:sm:3' () {}
}

there is error with The class Work.

public void processElement(Element elem) throws JaxmppException {
        if (log.isLoggable(Level.FINEST)) {
            log.finest("Recv (oid=" + SocketConnector.this.hashCode() + "): " + elem.getAsString());
        }
        if (elem != null && elem.getXMLNS() != null && elem.getXMLNS().equals("urn:ietf:params:xml:ns:xmpp-tls")) {
            onTLSStanza(elem);
        } else if (elem != null && elem.getXMLNS() != null &&
                "http://jabber.org/protocol/compress".equals(elem.getXMLNS())) {
            onZLibStanza(elem);
        } else {
            onResponse(elem);
        }
    }

    private void reconnect(final String newHost) {
        log.info("See other host: " + newHost);
        try {
            this.context.getSessionObject().setProperty(RECONNECTING_KEY, Boolean.TRUE);
            terminateAllWorkers();

            this.context.getSessionObject().clear(SessionObject.Scope.stream);
            this.context.getSessionObject().setProperty(SERVER_HOST, newHost);
            worker = null;
            reader = null;
            writer = null;

            this.context.getSessionObject().setProperty(RECONNECTING_KEY, Boolean.TRUE);

            log.finest("Waiting for workers termination");

            // start();
        } catch (JaxmppException e) {
            log.log(Level.WARNING, "Error on recconnect", e);
        }
    }

However , the method reconnect changed the host from nginx host to tigase host , but port is still 8042.

(1)

Added by w xy 3 months ago

Using SocketConnector

2018-12-13 14:26:50.856  INFO 4619 --- [           main] t.j.j.connectors.socket.SocketConnector  : DNS entry stored in session object: nginx host:8042
2018-12-13 14:26:54.114  INFO 4619 --- [           main] t.j.j.connectors.socket.SocketConnector  : Opening connection to nginx host:8042
2018-12-13 14:28:14.928  INFO 4619 --- [t-Worker-Thread] t.j.j.connectors.socket.SocketConnector  : See other host: ydsjbg-10-239-53-11.domain.localdomain
2018-12-13 14:28:14.928  INFO 4619 --- [t-Worker-Thread] t.j.j.connectors.socket.SocketConnector  : See other host: ydsjbg-10-239-53-10.domain.localdomain

Added by w xy 3 months ago

I got it, I wrote the configuration incorrectly , seeOtherHost {class: none} ---》 seeOtherHost (class: none){}.

Thanks o lot!

    (1-11/11)