How to build a replicated ehcache through firewall and not to die trying

It's assumed that:

  • You already have a java application and you have an ehcache instance running in your program with 1 cache configured to replicate.
  • You want to connect 1 instance to another instance you have in a remote machine
  • The remote machine you are connecting to is located behind a firewall.
  • You have been given access to only 1 port to make an ssh connection to the remote (firewalled) machine.
Ehcache uses RMI to connect the remote instances. When the cache in host 1 tries to connect to cache in host 2, RMI opens a new server socket in host 1 to listen for incoming connections from the host 2.
The problem here is that these random ports are not accesible to remote hosts because the hosts are behind a firewall.

So to fix it, we need to configure ehcache to only use 2 ports. The "remoteObjectPort" does the magic. So we have this ehcache.xml configuration:
  • 1 server port for the ehcache server to listen to other ehcache servers.
  • 1 server port for the ehcache cache to listen to incoming connections (this cache is the actual map in memory that is being replicated).
And the related properties are these. Inject it with System.setProperties(ehcacheProperties) before loading the ehcache instance in your program.
Open the 4 tunnels to the remote machine:

  • 1 local port for the ehcache server to listen to incoming connections from remote cache server
  • 1 local port for the ehcache cache for incoming connections from the remote cache
  • 1 remote port for remote ehcache server to listen incoming connections from our local host
  • 1 remote port for remote ehcache cache to listen to incoming connections from our local host

Run java programs on both machines (local and remote) with the "java.rmi.server.hostname" so the RMI server reports to the other RMI (the remote one) that it's address is "127.0.0.1" rather than any other IP it may has; so the tunnels can work. If you have any comment or suggestion please contact me.

Comments

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete
  2. Christmas has come and New Year is coming. One of the things I will do next year is to follow your new posts. It's because they provide what I need. Your articles are informative and great. Stay healthy and write more posts. Thanks
    Short Ride || Kindergarten Dress Up games for kids for school || Moto X3M 2 free on abcya3 games

    ReplyDelete
  3. Nice blog,I understood the topic very clearly,And want to study more like this.
    Data Scientist Course

    ReplyDelete
  4. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    data science course

    ReplyDelete
  5. It is perfect time to make some plans for the future and it is time to be happy. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!

    Data Science Course

    ReplyDelete
  6. I’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. nice one

    Data Science Training

    ReplyDelete
  7. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  8. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression
    data science interview questions

    ReplyDelete
  9. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up.
    java training in chennai

    java training in omr

    aws training in chennai

    aws training in omr

    python training in chennai

    python training in omr

    selenium training in chennai

    selenium training in omr

    ReplyDelete
  10. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
    course for analytics

    ReplyDelete
  11. It¦s truly a nice and helpful piece of info. I am satisfied that you simply shared this helpful information with us. Please keep us informed like this. Thanks for sharing.
    java training in chennai

    java training in velachery

    aws training in chennai

    aws training in velachery

    python training in chennai

    python training in velachery

    selenium training in chennai

    selenium training in velachery

    ReplyDelete
  12. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    educational course

    ReplyDelete
  13. Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

    360DigiTMG Data Science Course In Pune
    360DigiTMG Data Science Training In Pune

    Thank you..

    ReplyDelete
  14. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it. software training

    ReplyDelete
  15. Awesome article with valuable information it very helpful waiting for next blog update thank you.
    Data Analytics Course Online 360DigiTMG

    ReplyDelete
  16. Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

    Data Science Course In Hyderabad
    Data Science Training In Hyderabad
    Best Data Science Course In Hyderabad

    Thank you..

    ReplyDelete
  17. Thank you, I appreciate that I getting a lot of good and reliable information from your post. Thanks for sharing such kind of nice and wonderful post.

    Php Web Development Company Bangalore | Ecommerce Website Developer India | Internet Marketing Company in Bangalore | Ecommerce Website Company In India

    ReplyDelete
  18. Excellent blog with very impressive writing and unique content, information shared was very valuable thank you.
    Data Science Course in Hyderabad

    ReplyDelete
  19. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.

    Simple Linear Regression

    Correlation vs covariance

    KNN Algorithm

    Logistic Regression explained

    ReplyDelete
  20. Crypto-currency as a modern form of the digital asset has received a worldwide acclaim for easy and faster financial transactions and its awareness among people have allowed them to take more interest in the field thus opening up new and advanced ways of making payments. Crypto.com Referral Code with the growing demand of this global phenomenon more,new traders and business owners are now willing to invest in this currency platform despite its fluctuating prices however it is quite difficult to choose the best one when the market is full. In the list of crypto-currencies bit-coins is one of the oldest and more popular Crypto.com Referral Code for the last few years. It is basically used for trading goods and services and has become the part of the so-called computerized block-chain system allowing anyone to use it thus increasing the craze among the public, Crypto.com Referral Code.

    Common people who are willing to purchase BTC can use an online wallet system for buying them safely in exchange of cash or credit cards and in a comfortable way from the thousands of BTC foundations around the world and keep them as assets for the future. Due to its popularity, many corporate investors are now accepting them as cross-border payments and the rise is unstoppable. With the advent of the internet and mobile devices,information gathering has become quite easy as a result the BTC financial transactions are accessible and its price is set in accordance with people’s choice and preferences thus leading to a profitable investment with Crypto.com Referral Code. Recent surveys have also proved that instability is good for BTC exchange as if there is instability and political unrest in the country due to which banks suffer then investing in BTC can surely be a better option. Again bit-coin transaction fees are pretty cheaper and a more convenient technology for making contracts thus attracting the crowd. The BTC can also be converted into different fiat currencies and is used for trading of securities, for land titles, document stamping, public rewards and vice versa.

    Another advanced block-chain project is Ethereumor the ETH which has served much more than just a digital form of crypto-currency Crypto.com Referral Code and its popularity in the last few decades have allowed billions of people to hold wallets for them. With the ease of the online world,the ETH have allowed the retailers and business organizations to accept them for trading purposes, therefore, can serve as the future of the financial system.

    ReplyDelete
  21. Terrific post thoroughly enjoyed reading the blog and more over found to be the tremendous one. In fact, educating the participants with it's amazing content. Hope you share the similar content consecutively.

    artificial intelligence certification in bhilai

    ReplyDelete
  22. Really wonderful blog completely enjoyed reading and learning to gain the vast knowledge. Eventually, this blog helps in developing certain skills which in turn helpful in implementing those skills. Thanking the blogger for delivering such a beautiful content and keep posting the contents in upcoming days.

    Data Science Course in Bhilai

    ReplyDelete
  23. Extraordinary blog went amazed with the content that they have developed in a very descriptive manner. This type of content surely ensures the participants to explore themselves. Hope you deliver the same near the future as well. Gratitude to the blogger for the efforts.

    Digital Marketing Course

    ReplyDelete
  24. Really nice and interesting blog information shared was valuable and enjoyed reading this one. Keep posting. Thanks for sharing.
    Data Science Training in Hyderabad

    ReplyDelete
  25. Nice Information Your first-class knowledge of this great job can become a suitable foundation for these people. I did some research on the subject and found that almost everyone will agree with your blog.
    Cyber Security Course in Bangalore

    ReplyDelete
  26. Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
    Cyber Security Training in Bangalore

    ReplyDelete

  27. Great article with valuable information found very resourceful and enjoyed reading it waiting for next blog update thanks for sharing.
    Ethical Hacking Course in Bangalore

    ReplyDelete

Post a Comment

Popular posts from this blog

Android 3D Model Viewer Open Source

Java 9 Process API