Spring boot

To run a spring boot application by itself (simply using java -jar) we can build executable jar that contains all dependencies inside it. For that we need bootJar task. jar task is not enough. If we want to deploy application to a container, we then need to generate a war file.

jar or war only builds normal archives. bootJar and bootWar builds executable archives.Applying java plugin automatically adds bootRun task that builds a jar we can execute using java -jar. Applying a war plugin adds a bootWar task that builds the war we can execute.

The assemble task is automatically configured to depend upon the bootJar task so running assemble (or build) will also run the bootJar task. Running assemble or build will also run the bootWar task

 

Rabbit MQ

It is a powerful queuing mechanism with connecting support from multiple programming languages.

Install Rabbit MQ on Mac :

A brew for the RabbitMQ server is available from HomebrewNote: You may not be able to install the RabbitMQ brew from inside a firewall.

Install the Server

Before installing make sure you have the latest brews:

brew update

Then, install RabbitMQ server with:

brew install rabbitmq

Run RabbitMQ Server

The RabbitMQ server scripts are installed into /usr/local/sbin. This is not automatically added to your path, so you may wish to add
PATH=$PATH:/usr/local/sbin to your .bash_profile or .profile. The server can then be started with terminal command : rabbitmq-server.

All scripts run under your own user account. Sudo is not required.

Aerospike

Aerospike is a no-sql and non-relational database. Aerospike stores data in Flash(which is Cache) and also on the disk : Usually temporary data or data with ttl is stored in cache and data that should be permanent is stored on disk.

Comparison of Aerospike with relational database terminology :
Namespace is Schema.
Sets are tables.
Bins are columns.
User defined functions are stored procedures for aerospike.

show sets : will show all namespaces and sets.

aql is the prompt to connect to aerospike database for querying. There is also a dashboard that lets you see aerospike data (but no querying).

You cannot create namespace on the fly or part of the code, it needs to be done as part of the config file. So creating a new namespace needs a restart.
If you have 2 nodes in aerospike, there is no master slave relation : you can have both identical and have same data. 2 nodes, replication factor is 2 : same data will be present on both servers.
If you want features like ordering by or group by, write a UDF (stored procedure) that does the job.
You can filter by bin which returns multiple records, you need to create a secondary index.

/etc/aerospike/aerospike.conf : The main config file.

Instructions for setting up Aerospike on a Mac :

Using Vagrant & Virtual Box.

  1. Install Vagrant (https://releases.hashicorp.com/vagrant/1.8.1/vagrant_1.8.1.dmg)
  2. Install Virtual Box (http://download.virtualbox.org/virtualbox/5.0.14/VirtualBox-5.0.14-105127-OSX.dmg)
  3. Create an Aerospike Directory
    $ mkdir ~/aerospike-vm && cd ~/aerospike-vm
  4. Initialize the Aerospike Virtual Machine
    $ vagrant init aerospike/centos-6.5
  5. Run Aerospike. To start up the virtual machine and asd, run the following from the command prompt
    $ vagrant up
  6. Verify Aerospike and AMC are Running
    $ vagrant ssh -c “sudo service aerospike status”
    # asd (pid XXXX) is running…
    # Connection to 127.0.0.1 closed.
    $ vagrant ssh -c “sudo service amc status”
    # Retrieving AMC status….
    # AMC is running.
    # Connection to 127.0.0.1 closed
  7. Verify server log
    $ vagrant ssh -c “sudo grep -i cake /var/log/aerospike/aerospike.log”
    # **********Aerospike Database Server is running!
    # **********Aerospike Monitoring Console is running!
    # Connection to 127.0.0.1 closed.
  8. Make sure AMC is running and visit the following URL: http://localhost:8081/
  9. Connect to aerospike VM
    $ vagrant sshReference: http://www.aerospike.com/docs/operations/install/vagrant/mac/

Note:*** After installing latest version of aerospike,  please restart your machine to avoid caching issue if you have old version of aerospike installed.

SBT (Simple build tool)

This is a build tool that builds your scala project which involves downloading all the dependencies mentioned in your scala project file.

Debugging Scala SBT with intellij :

At the command line, start sbt :
> sbt

then, in sbt shell:

> project <project name in build.scala file>
[info] Set current project to <projectname>
re-start — -Dbuild.env=<envName> -Dconfig.file=<config_file_loc> –Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

[info] Application <project> not yet started
[info] Starting application <project> in the background …
<proj> Starting <project_path>.main()
[success] Total time: 1 s
> <proj> Listening for transport dt_socket at address: 5005

Go back to IntelliJ, and in Run->edit configurations->Remote click the + to create a copy
then edit that copy to give it a name
Put the address from above (here 5005) into that for the port. Click ok to save it, then Run->Debug <name you chose> should attach to the session (IntelliJ calls it a Frame)
make sure to set a break point which will get hit. Use Postman to send the appropriate request to kick it off

 

Charles Proxy

Charles proxy is a tool we can use to monitor device outgoing traffic. One usage for this is to troubleshoot issues with app on a phone. Using this tool, we can see all outbound traffic including the request and response payloads.

Setting it up involves multiple steps :

  1. Download Charles Proxy on your local machine and launch.
    • If necessary, send an IT Support ticket to obtain a license. Then in the Help tab, click on Register license and enter Certificate info.
  2. In the Proxy tab,
    • For “SSL Proxying Settings…“, add the following:
      • Host: *
      • Port: 443
    • For “Proxy Settings“, ensure the following:
      • In the “Proxies” tab,
        • Set Port: 8888
        • Enable transparant HTTP proxying
      • In the “Mac OS X” tab,
        • Enable Mac OS X proxy
        • Enable Use HTTP Proxy
        • Enable Mac OS X proxy at startup
  3. In the Help tab,
    • Click SSL Proxying > Install Charles Root Certificate > Trust it in your Keychain (for Mac)
  4. Check your iOS/Android device’s wireless settings and make sure it’s the same wireless network on your local machine  ie: “phunware-an”
  5. On your device’s wireless network settings, set your device’s HTTP Proxy settings to “Manual”
    • iOS
      • Server : Your laptop/computer’s IP address
      • Port : Specified in Step 2 (usually 8888)
    • Android (Hold the wireless network name > Modify network > Show advanced options
      • Proxy Hostname : Your laptop/computer’s IP address
      • Proxy Port : Specified in Step 2 (usually 8888)
  6. On Charles Proxy, accept a prompt that a connection is being made.
  7. On the device, open a browser and go to http://www.charlesproxy.com/getssl and install the certificate. If the page is unable to load or you don’t see the certificate prompt – turn off your wireless settings, reload that page, turn back on your wireless settings, and hit refresh.
  8. iOS – Install and trust it in Settings > General > Profiles & Device Management. Android – Give the certificate a name and save.
  9. For iOS 10 and above, you have to enable trust in  Settings > General >  About > Certificate Trust Settings > Enable Full Trust For Root Certificates
  10. You are now able to see device network traffic.

Best Practices in the world of Software

Here I will talk about best practices and some ways to increase application performance.

  • If you want an application to process more requests , one option is to increase the number of servers on which the application is running – This can be done easily on AWS servers. Please note that this can have some side effects such as increase in database connections if application communicates with a database – Make sure there are no implications before increasing the number of instances of an application.
  • Try to increase the RAM on the server application is running. This can help improve the performance – Observing memory usage on the server can give better idea : free -m on the server will give the memory info.

Best Practices :

  • If your application is running on multiple servers, make sure

Intellij

I feel Intellij is one of the best IDE for Java, Scala development. Community edition should suffice for most of development purposes.

I prefer atom IDE for Node.js development.

You can open the terminal window in Intellij itself : View -> Tool Windows -> Terminal
This way you can run all terminal commands on the project without having to open terminal application separately.

To open a project in same window :

intellij-open-project-same-window

To Search for text in entire project : ctrl + shift + f

Search for files in the project :  cmd + shift + n

To search and replace text in entire project : ctrl + shift + r

Double press shift -> Lets you search in entire project.

command + E -> Shows recently used files.

To view all tool windows(Terminal, Gradle build, etc) on a fresh Intellij install -> View -> Tool buttons

Running projects in Intellij :

You can right click on any project and run it directly from Intellij.

If you see Abnormal Build Process Termination error in intellij when running or debugging a java project, it may be because you are using latest version of Intellij but an older version of java is setup for your project.

Update your project SDK to 9.0 – Right click on Project -> open module settings -> Project -> Project SDK : 9.0

Compilation error for projects in Intellij :

Java projects in Intellij has modules -> Right click on Project -> open module settings -> modules -> You will mostly have main module and test module ->
Make sure src and resources are pointing to correct project directories for main module. Also make sure test and resources are pointing to correct project directories for test module. This is how intellij understands the project and compiles it.

Node JS

Recommended tool for Node development is Atom (developed by folks from github)

To open a node project in eclipse, you need to have nodeclipse plugin installed in your eclipse.
To open an existing node project :

File -> New Project -> Node.js Project -> Uncheck ‘Use Default Location’ -> Browse -> Navigate to your project location -> give ‘Project Name’ same as your project name -> Finish.

Middleware in node code is functionality that executes between request and response. You can provide some functionality in the middleware that will be executed for sure for each request.
app.use can be used to add all code you need to be executed in the middleware. All middleware modules(which are under app.use) are executed one after the other.

Async node module : we can write code that executes either in parallel, series or waterfall mode. All these functions assume you follow the Node.js convention of providing a single callback as the last argument of your asynchronous function — a callback which expects an Error as its first argument — and calling the callback once.

Make sure to always return when calling a callback early, otherwise you will cause multiple callbacks and unpredictable behavior in many cases.