The energy of wireless sensor networks (WSNs) is generally powered by limited and portable batteries. However, there are some specific scenarios where the nodes can gain energy continuously, such as the electric energy data collection, the power line monitoring and using renewable energy. Meanwhile, due to the centralized traffic pattern in WSNs, congestion occurs easily and has a negative impact on the network performance, namely, decreasing throughput and increasing energy consumption. In this paper, a solution to sufficiently maintain the energy efficiency and avoid congestion for energy-unlimited WSNs is presented. Based on the similarity between data forwarding in WSNs and water transmission in pipeline, a traffic-aware and energy-efficient routing (TER) algorithm is proposed. The TER algorithm is designed by constructing a pipeline model in terms of physical distance and traffic load. The goal of this basic approach is to force the packets to steer clear of obstacles created by congestion and eventually move toward the sink. The simulation results show that the proposed solution generates better performance in terms of the global energy consumption, timeliness and reliability as compared to the other two algorithms.