Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Local port forwarding

DZone's Guide to

Local port forwarding

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

A colleague and I ran into an interesting problem today which we wanted to use local port forwarding to solve.

In our environment.rb file we have a Solr instance url defined like so:

SOLR_CONFIG = {
:service_url => "http://some.internal.address:9983/solr/sco_slave_1"
}

It’s defined like that because our colleagues in Chicago have setup a Solr instance on a test environment and all the developers hit the same box.

In Pune everyone has Solr configured on their own box so we really wanted to configure that url to be ‘localhost’ on port ’8983′.

Several other colleagues have just changed their environment.rb file and then remember not to check that in.

I always forget about that type of thing though so I wanted to find a work around.

We started by putting the following in /etc/hosts:

127.0.0.1		some.internal.address

Having done that we needed to forward anything coming in on port 9983 to 8983 to complete the forwarding.

I think there’s a proper way of doing this using iptables but we didn’t want to shave the yak and hence used this tcpforward perl script:

./tcpforward -k -l some.internal.address:9983 -c 127.0.0.1:8983

If anyone knows a better way or the proper way to do this I’d be interesting in hearing about that but for now this does the job!

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Mark Needham, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}